3 Replies Latest reply on Apr 22, 2008 7:58 PM by bostone

    selectOneMenu fails to bind value

    bostone

      Hi guys,

      I have a problem with pretty simple case of two selectOneMenu dropdowns. I'm using exposed model pattern so the first dropdown is bind to the model object with converter provided. Second dropdown contains only two hardcoded values - Active and Inactive, and bound to the 'Status' property of the model object. The problem is, when I select value from the first list, the second one will always receive Null for a value and hence 'Active" option is always displayed. If I replace second dropdown with just a text field, the 'Status' property will be properly bound to whatever value was extracted from the db.
      It seems that 'Status' property of the model object gets overwritten during binding phase if I try to bind it to the SelectOneMenu value.

      So here's stripped down version of two dropdpwns

       <h:form id="createApplicationForm">
       <h:selectOneMenu id="appList"
       value="#{applicationBean.selectedApp}"
       converter="#{namsUserConverter}">
       <f:selectItem itemValue="#{applicationBean.defaultApp}"
       itemLabel="New" />
       <f:selectItems value="#{applicationBean.apps}" />
       <a4j:support action="#{applicationBean.select}" event="onchange"
       ajaxSingle="true"
       reRender="userAppStat" />
       </h:selectOneMenu>
       <a4j:outputPanel ajaxRendered="true">
       <h:selectOneMenu id="userAppStat"
       value="#{applicationBean.selectedApp.status}">
       <f:selectItem itemLabel="Active" itemValue="A" />
       <f:selectItem itemLabel="Inactive" itemValue="I" />
       </h:selectOneMenu>
       </a4j:outputPanel>
       </h:form>
      


      Partial managed and model beans
      public class CreateApplicationBean
      {
       private List<SelectItem> apps;
       private AppUser selectedApp;
       /**
       * @return the defaultUser
       */
       public AppUser getDefaultApp()
       {
       return new AppUser();
       }
      
       public void select(){...}
      }
      
      public class AppUser
      {
       private String status;
      }
      


      Please let me know if I'm missing anything

        • 1. Re: selectOneMenu fails to bind value
          bostone

          Now, I tried a few other arrangements. If I remove ajaxSingle="true" from the first box, then not surprisingly Status property in the bound model object will be updated with a current value of the second select (not what I need)
          If I have ajaxSingle="true" then again the select property will be set to null.
          Then I tried to put first select inside the a4j:region in which case I get the right value for the property, however second select will not be refreshed.

          Can anyone help with this? I'm really banging my head at this point

          • 2. Re: selectOneMenu fails to bind value
            ilya_shaikovsky

            https://ajax4jsf.dev.java.net/servlets/ProjectDocumentList?folderID=5320&expandFolder=5320&folderID=0

            There our old examples was commited. Just download dropDownBoxes example, change ajax4sjf to RF jars and deploy to tomcat 5.5.

            Fully working example.

            • 3. Re: selectOneMenu fails to bind value
              bostone

              Ilya, thanks a lot,

              This example has some limitations. First the managed bean (Bean) is defined in the session scope. The instance it's placed into request scope summary button stops working. Second - I changed the code to use complex Vehicle object and converter instead of simply mapping form fields to bunch of unrelated lists. That broke the code further.
              I'm wondering if you (or anyone else) can look at the modified code and recommend the solution. Basically, to reiterate, my client's requirement is to stay within request scope and map form fields directly to model objects rather than primitive data ans lists

              The modified example can be downloaded from here http://www.box.net/shared/q5dzl5f0o0