2 Replies Latest reply on Mar 25, 2010 12:13 AM by Tim Evers

    selectOneMenu noSelectionLabel not selectable with ajax validation

    Vadim Berezniker Newbie


      <s:decorate id="mode" template="/layout/edit.xhtml">
          <ui:define name="label">Item</ui:define>
          <h:selectOneMenu value="#{itemHome.instance.mode}">
              <s:selectItems var="_mode" value="#{itemModes.allItemModes}" label="#{_mode.label}"
                      noSelectionLabel="" 
              />
              <s:convertEnum />
              <a:support event="onchange" reRender="mode" bypassUpdates="true" ajaxSingle="true" />
          </h:selectOneMenu>
      </s:decorate>





      Drop down is populated with values of an enum. If you select the no selection option in the drop down, the selection will reset to the value of #{itemHome.instance.mode} on the ajax update.
      When the component value is updated, the NoSelectionConverter sets the value to null. When the component is rerendered, UIOutput.getValue() is called which checks if the value is null in which case it ignores the null and refers back to the el (#{itemHome.instance.mode}) which renders the old value.


      I don't know enough about JSF/Seam internals to say whether the problem lies in JSF or Seam. I would appreciate any feedback.


        • 1. Re: selectOneMenu noSelectionLabel not selectable with ajax validation
          Vadim Berezniker Newbie

          Still having this problem...


          Unless bypassUpdates is disabled, the select will always revert to the previous value.

          • 2. Re: selectOneMenu noSelectionLabel not selectable with ajax validation
            Tim Evers Master

            Why do you have


            bypassUpdates="true"
            



            From the richfaces documentation


            bypassUpdates


            If "true", after process validations phase it skips updates of model beans on a force render response. It can be used for validating components input
            



            This is just a fundamental problem of the 'null' value and how it is used.


            Null is overloaded by almost every application out there to mean too many different things and this is just one of them. So in the JSF world a lot of times null means that the variable has not been initialised yet and thus it should make a call to the appropriate getter to initialise it.


            Thus, in your situation because you have specifically said do not update my bean with the value in this drop down by setting bypassUpdates to true, the null value of the NoSelectionLabel is causing the getter to fire which is always going to return the last value that posted in which an UpdateModel phase was executed.


            It would be nice to know why you even have an ajax call on the onchange event for this component.
            From what I can see it just looks like an attempt to do input validation. If that's the case then don't bother. Just limit the drop down to the items in the list and they can never be wrong. (Well, almosts never, but ajax validation wont help anyway in the circumstances where a bogus value gets in there). What I mean by this is don't allow users to type values into the drop down.


            If the input validation is all you are trying to achieve then take out the ajax part completely.


            If you are doing anything other then input validation then I fail to see how using bypassUpdates=true is the right thing to do. (That doesn't mean there isn't a valid reason for it, I just can't think of it right now :P )


            I may not have solved your problem, but hopefully I have at least helped you understand why it happens.


            Maybe if you post a little more info about what the ajax is for we can work on a solution :)