6 Replies Latest reply on Jul 23, 2007 6:51 PM by smithbstl

    "h:selectOneMenu" with Ajax4JSF passing selection to backing

    raviies

      I'm a JSF, Seam newbie; Excuse me if this is not the right forum

      I have a form with a dropdown; I want to pass my selection on the "fly" to the backing bean by using Ajax4JSF;

      Unfortunately I'm not able to able to pass on the "fly"; However form submit seems to work

      Here's my code snippet:

      <f:view>
      <s:validateAll>
      <h:form>
      <h:panelGrid columns="2">
      .....
      
       SRB DataTransferScheme *
       <h:selectOneMenu id="dataTransferCombobox" value="#{loginBean.dataTransferScheme}"
       <a4j:support event="onchange" action="#{loginBean.setAuthFields(loginBean.dataTransferScheme)}"
       ajaxSingle="true" immediate="true"/>
       </h:selectOneMenu>
      </h:panelGrid>
      .....
      
      <h:commandButton value="Login" action="#{login.login}"/>
      </s:validateAll>
      </h:form>
      
      //LoginBean.java: [the Backing bean]
      
      public void setAuthFields(String dataTransferScheme)
      {
       System.out.println("dataTransferScheme : "+dataTransferScheme);
      }
      


      I appreciate any suggestions, feedback

      TIA
      Ravi


        • 1. Re:
          damianharvey

          when you change the value of your dropdown the onchange event launches and does 2 things:
          1. Updates the value of dataTransferScheme in the loginBean
          2. Calls the setAuthFields method in the loginBean.

          The way you have it, you are trying to pass the updated value of dataTransferScheme into #2 when the page doesn't yet have this value.

          Try changing your setAuthFields method to have no parameters and instead use the value of dataTransferScheme that has been applied.

          public void setAuthFields()
          {
           System.out.println("dataTransferScheme : "+this.dataTransferScheme);
          }


          Also you may want to get rid of immediate=true. I can't recall if this stuffs up the application of values to the Bean (although I think that it bypassUpdates).

          Cheers,

          Damian.

          • 2. Re:
            raviies

            Thanks Damian

            I did exactly as you suggested but result is same:
            "dataTransferScheme : null"

            The value is being set to null. Any suggestions?

            TIA
            Ravi

            • 3. Re:

              I don't understand where the value for dataTransferScheme is supposed to come from.

              Typically you should be using a s:selectItems/f:selectItem/f:selectItems to get a list of values for your menu. Then menu then chooses one and passes that value to your backing bean.

              <f:view>
              <s:validateAll>
              <h:form>
              <h:panelGrid columns="2">
              .....
              
               SRB DataTransferScheme *
               <h:selectOneMenu id="dataTransferCombobox" value="#{loginBean.dataTransferScheme}"
               <a4j:support event="onchange" action="#{loginBean.setAuthFields(scheme)}"
               ajaxSingle="true" immediate="true"/>
               <s:selectItems label="#{scheme}" value="#{schemes}"
               var="scheme"/>
               </h:selectOneMenu>
              </h:panelGrid>
              .....
              
              <h:commandButton value="Login" action="#{login.login}"/>
              </s:validateAll>
              </h:form>
              
              //LoginBean.java: [the Backing bean]
              
              //system.out.println is ugly, use Seam's logger support
              @Logger
              Log log;
              
              @Out
              private List<String> schemes;
              
              @Factory("schemes")
              public void fillSchemes() {
              //Fill your list here
              }
              
              
              public void setAuthFields(String dataTransferScheme)
              {
               log.info("dataTransferScheme : "+dataTransferScheme);
              }


              • 4. Re:
                raviies

                Thanks smithbstl:

                I don't understand where the value for dataTransferScheme is supposed to come from.


                My Login Bean has following getter to fill up the comboBox and it works alright:

                public List<String> getAvailableDataTransferSchemes()
                 {
                 List<String> result = new ArrayList<String>();
                 for(int i=0; i<dataTransferSchemeArray.length; i++)
                 result.add(dataTransferSchemeArray);
                 return result;
                 }


                Coming to the original problem I'm getting dataTransferScheme = "" in my backingBean. Am I missing something obvious?

                TIA
                RAVI



                • 5. Re:
                  raviies

                  Excuse me for not describing my setup earlier:

                  1> Tomcat 6.0

                  2> Embedded Jboss: embedded-jboss-beta2

                  3> JDK 1.5.0_12-b04

                  4> Interestingly my page source has action empty :

                  <a4j:support event="onchange" action="" ajaxSingle="true"></a4j:support>
                  <select id="j_id2:dataTransferCombobox" name="j_id2:dataTransferCombobox" size="1"> <option value="PLAIN_TEXT">PLAIN_TEXT</option>
                   <option value="SRB_ENCRYPT" selected="selected">SRB_ENCRYPT</option>
                   <option value="KERBEROS_INTEGRITY">KERBEROS_INTEGRITY</option>


                  TIA
                  RAVI

                  • 6. Re:

                    perhaps removing the "set" from setAuthFields since EL may be confused because this conforms to javabeans syntax

                    try this

                    action="#{loginBean.authFields(....)"


                    or rename your setAuthFields method to something without get or set