a4j:support and SelectOneMenu
alex_ph Mar 31, 2007 2:38 AMHi,
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