Ajax Echo-Tutorial doesn't work!!!
markus2000 Jun 13, 2008 8:57 AMHi,
i have testet the Ajax Echo-Tutorial from richfaces. It works but with the following simple enhancments it doesn't work:
<webuijsf:form binding="#{Page1.form1}" id="form1"> <h:selectOneRadio id="fruit" value="#{fruitInfoBean.fruit}" valueChangeListener="#{fruitInfoBean.changeFruit}"> <f:selectItems value="#{fruitInfoBean.fruits}"/> <a4j:support event="onchange" ignoreDupResponses="true" reRender="varietyInfo,variety"/> </h:selectOneRadio> <h:selectOneMenu id="variety" value="#{fruitInfoBean.variety}"> <f:selectItems value="#{fruitInfoBean.varieties}"/> </h:selectOneMenu> <h:outputText id="varietyInfo" value="#{fruitInfoBean.varietyInfo}" /> <br/> <rich:panel id="panel13" header="Simple Echo"> <h:inputText id="input12" size="50" value="#{echoBean.text}" > <a4j:support event="onkeyup" reRender="rep"/> </h:inputText> <h:outputText value="#{echoBean.text}" id="rep"/> </rich:panel> </webuijsf:form>
EchoBean.java: public class EchoBean { private String text = null; public EchoBean() {} public String getText() { return text; } public void setText(String text) { this.text = text; } }
FruitInfoBean.java: public class FruitInfoBean { private SelectItem[] fruits = { new SelectItem("Pear", "Pear"), new SelectItem("Apple", "Apple"), new SelectItem("Orange", "Orange"), new SelectItem("Peach", "Peach") }; private SelectItem[] varietiesPear = { new SelectItem("Pear1", "Pear1") }; private SelectItem[] varietiesApple = { new SelectItem("Apple1", "Apple1"), new SelectItem("Apple2", "Apple2") }; private SelectItem[] varietiesOrange = { new SelectItem("Orange1", "Orange1"), new SelectItem("Orange2", "Orange2") }; private SelectItem[] varietiesPeach = { new SelectItem("Peach1", "Peach1"), new SelectItem("Peach2", "Peach2"), new SelectItem("Peach3", "Peach3") }; private SelectItem[] varieties = null; private String fruit = fruits[1].getLabel(); private String variety = "no one"; private String varietyInfo = "no one"; public FruitInfoBean() {} public String getFruit() { return fruit; } public SelectItem[] getFruits() { return fruits; } public void changeFruit(ValueChangeEvent event) { String str = (String)event.getNewValue(); variety = str; varietyInfo = str + " is now selected and active!!!"; if (str.startsWith("Pear")) { varieties = varietiesPear; } else if (str.startsWith("Apple")) { varieties = varietiesApple; } else if (str.startsWith("Orange")) { varieties = varietiesOrange; } /*else { varieties = varietiesPeach; }*/ } public String getVariety() { return variety; } public SelectItem[] getVarieties() { if (varieties == null) { varieties = new SelectItem[] { new SelectItem("Peach", "Peach") }; return varieties; } return varieties; } public String getVarietyInfo() { return varietyInfo; } }
What I have added is a radio-selection of fruits and a combobox of fruit types. If a fruit is selected (e.g. Orange) the combobox is updated with new values. The interesting effect now is:
If i type at the echo server and then select e.g. Orange the "changeFruit" event is called and after this i type again at the echo server no "setText" event occurs on the server. The echo-server doesn't work.
It looks like that the "state information" gets lost. Thanks in advance.
cu
Markus