5 Replies Latest reply on Apr 2, 2007 11:12 AM by ilya_shaikovsky

    a4j:support and SelectOneMenu

    alex_ph

      Hi,
      I don't know if this question counts as a a4j only problem. I hope you could help me here.
      Ok, I have a JSP:

      <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
      <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
      <%@ taglib uri="https://ajax4jsf.dev.java.net/ajax" prefix="a4j" %>
      <%@ taglib uri="http://richfaces.ajax4jsf.org/rich" prefix="rich" %>
      
      <f:subview id="page1Wizard">
      
       <a4j:outputPanel ajaxRendered="true">
       <h:messages />
       </a4j:outputPanel>
      
       <h:form>
       <h:panelGrid styleClass="panelGrid" columns="2">
       <h:outputText value="Option 1:" />
      
       <h:panelGroup>
       <h:selectOneMenu value="#{testSelect.currentOption1}">
       <f:selectItems value="#{testSelect.option1List}"/>
       <a4j:support event="onchange" ajaxSingle="true" action="#{testSelect.changeOption2List}" reRender="Option2, Option3" />
       </h:selectOneMenu>
       </h:panelGroup>
      
       <h:outputText value="Option 2" />
       <h:panelGroup id="Option2">
       <h:selectOneMenu value="#{testSelect.currentOption2}">
       <f:selectItems value="#{testSelect.option2List}"/>
       <a4j:support event="onchange" ajaxSingle="true" action="#{testSelect.changeOption3List}" reRender="Option3" />
       </h:selectOneMenu>
       </h:panelGroup>
      
       <h:outputText value="Option 3:" />
       <h:panelGroup id="Option3">
       <h:selectOneMenu value="">
       <f:selectItems value="#{testSelect.option3List}"/>
       <a4j:support event="onchange"/>
       </h:selectOneMenu>
       </h:panelGroup>
      
       <h:commandButton value="OK" />
       <h:commandButton onclick="Richfaces.hideModalPanel('mp')" value="CANCEL" />
       </h:panelGrid>
       </h:form>
       </f:subview>
      


      And the responsible Bean look like this:
      public class TestSelect {
       private java.lang.String currentOption1;
       private java.lang.String currentOption2;
       private String currentOption3;
      
       private ArrayList<SelectItem> option1List;
       private ArrayList<SelectItem> option2List;
       private ArrayList<SelectItem> option3List;
      
       public TestSelect() {
      
       option1List = new ArrayList<SelectItem>();
       option2List = new ArrayList<SelectItem>();
       option3List = new ArrayList<SelectItem>();
      
       option1List.add(new SelectItem("option1-SELECT1","O1-Select1"));
       option1List.add(new SelectItem("option1-SELECT2","O1-Select2"));
       option1List.add(new SelectItem("option1-SELECT3","O1-Select3"));
      
       option2List.add(new SelectItem("option2-SELECT1","O2-Select1"));
       option2List.add(new SelectItem("option2-SELECT2","O2-Select2"));
       option2List.add(new SelectItem("option2-SELECT3","O2-Select3"));
      
       option3List.add(new SelectItem("option3-SELECT1","O3-Select1"));
       option3List.add(new SelectItem("option3-SELECT2","O3-Select2"));
       option3List.add(new SelectItem("option3-SELECT3","O3-Select3"));
      
       }
      
      
       public void changeOption2List(){
       System.out.println("IN changeOption2List: ");
       System.out.println(" Option 1: "+ currentOption1);
       }
      
       public void changeOption3List(){
       System.out.println("IN changeOption3List: ");
       System.out.println(" Option 1: "+ currentOption1);
       System.out.println(" Option 2: "+ currentOption2);
       }
      
       public java.lang.String getCurrentOption1() {
       return currentOption1;
       }
      
       public void setCurrentOption1(java.lang.String currentOption1) {
       this.currentOption1 = currentOption1;
       }
      
       public java.lang.String getCurrentOption2() {
       return currentOption2;
       }
      
       public void setCurrentOption2(java.lang.String currentOption2) {
       this.currentOption2 = currentOption2;
       }
      
       public String getCurrentOption3() {
       return currentOption3;
       }
      
       public void setCurrentOption3(String currentOption3) {
       this.currentOption3 = currentOption3;
       }
      
       public ArrayList<SelectItem> getOption1List() {
       return option1List;
       }
      
       public void setOption1List(ArrayList<SelectItem> option1List) {
       this.option1List = option1List;
       }
      
       public ArrayList<SelectItem> getOption2List() {
       return option2List;
       }
      
       public void setOption2List(ArrayList<SelectItem> option2List) {
       this.option2List = option2List;
       }
      
       public ArrayList<SelectItem> getOption3List() {
       return option3List;
       }
      
       public void setOption3List(ArrayList<SelectItem> option3List) {
       this.option3List = option3List;
       }
      }
      


      If I start the program and select the first selectOneMenu the System.output is ok:

      IN changeOption2List:
      Option 1: option1-SELECT2


      But if I use the second drop-down-box the value of the Option1 is "null":

      IN changeOption3List:
      Option 1: null
      Option 2: option2-SELECT2


      Does this works like it should? Have I to bind every "currentOption" to an UIComponent? I hope you could give me a hint, how I could obtain the Option1 value in the method changeOption3List.

      Thnx
      Alex

        • 1. Re: a4j:support and SelectOneMenu

          what is the scope of testSelect bean?

          • 2. Re: a4j:support and SelectOneMenu
            alex_ph

            Hi, its a session bean:

            <managed-bean>
             <managed-bean-name>testSelect</managed-bean-name>
             <managed-bean-class>beans.TestSelect</managed-bean-class>
             <managed-bean-scope>session</managed-bean-scope>
            </managed-bean>
            



            I've got another short question wherefore I don't want to open an extra post: How could I disable the vertical scrollbar of the simpleTogglePanel? It appears on Mozilla 2.0.0.3 but in IE and Opera its not enabled.

            Thnx alot

            • 3. Re: a4j:support and SelectOneMenu

              Use a4j:region around the selectOneMenu instead of ajaxSingle

              • 4. Re: a4j:support and SelectOneMenu
                alex_ph

                Thanks for this hint, but I think I need a bit more help because I don't really understand how I should use a4j:region in the right way. I deleted the ajaxSingle="true" and tried to set the a4j:region inside the form, around every selectOneMenu but I have no clue how I could avoid that the Option1 is null after I changed the value of the second selectOneMenu.

                Thats one try who doesn't work:

                <h:panelGroup>
                 <a4j:region>
                 <h:selectOneMenu value="#{testSelect.currentOption1}">
                 <f:selectItems value="#{testSelect.option1List}"/>
                 <a4j:support event="onchange" action="#{testSelect.changeOption2List}" reRender="Option2, Option3" />
                 </h:selectOneMenu>
                 </a4j:region>
                </h:panelGroup>
                
                <h:outputText value="Option 2" />
                <h:panelGroup id="Option2">
                 <a4j:region>
                 <h:selectOneMenu value="#{testSelect.currentOption2}">
                 <f:selectItems value="#{testSelect.option2List}"/>
                 <a4j:support event="onchange" action="#{testSelect.changeOption3List}" reRender="Option3" />
                 </h:selectOneMenu>
                 </a4j:region>
                </h:panelGroup>
                
                <h:outputText value="Option 3:" />
                <h:panelGroup id="Option3">
                 <a4j:region>
                 <h:selectOneMenu value="">
                 <f:selectItems value="#{testSelect.option3List}"/>
                 <a4j:support event="onchange"/>
                 </h:selectOneMenu>
                 </a4j:region>
                </h:panelGroup>
                


                Thnx Alex

                • 5. Re: a4j:support and SelectOneMenu
                  ilya_shaikovsky

                  Set renderRegionOnly attribute on the region to "false" to reRender parts of outside of the current region.