This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Hands On Software Engineering with Python and have Brian Allbey on-line!
See this thread for details.
Win a copy of Hands On Software Engineering with Python this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
Bartenders:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

JSF ajax listner not working for dropdown  RSS feed

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

i am trying to add ajax for a dropdown and i have added the below code in my xhtml but the listner is not getting called once there is a change.

XHTML Code:
<h:selectOneMenu
value="#{loginBean.dropDownValue}" itemValue="#{dropDownValue}">
<f:selectItem itemValue="****select***" />
<f:selectItems value="#{loginBean.testDropDown}"/>
<f:ajax event="change" listner="#{loginBean.changeDropDownOne}" render="testDropDownTwoValue" />
</h:selectOneMenu>


method in the bean:

public List<SelectItem> changeDropDownOne() {
System.out.println("$$$$$$$$$$");
String dp = getDropDownValue();
if(dp != null) {
System.out.println("**********************getTestDropDownTwo********************************"+dp);
if(dp.equalsIgnoreCase("One")) {
testDropDownTwo.add(new SelectItem("One - One"));
testDropDownTwo.add(new SelectItem("One - Two"));
testDropDownTwo.add(new SelectItem("One - Three"));
testDropDownTwo.add(new SelectItem("One - Four"));
} else if(dp.equalsIgnoreCase("Two")) {
testDropDownTwo.add(new SelectItem("Two - One"));
testDropDownTwo.add(new SelectItem("Two - Two"));
testDropDownTwo.add(new SelectItem("Two - Three"));
testDropDownTwo.add(new SelectItem("Two - Four"));
}else if(dp.equalsIgnoreCase("Two")) {
testDropDownTwo.add(new SelectItem("Three - One"));
testDropDownTwo.add(new SelectItem("Three - Two"));
testDropDownTwo.add(new SelectItem("Three - Three"));
testDropDownTwo.add(new SelectItem("Three - Four"));
}else {
testDropDownTwo.add(new SelectItem("Four - One"));
testDropDownTwo.add(new SelectItem("Four - Two"));
testDropDownTwo.add(new SelectItem("Four - Three"));
testDropDownTwo.add(new SelectItem("Four - Four"));
}
}
return testDropDownTwo;
}


Please help me in this regard

KK
 
Bartender
Posts: 3648
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no "listner" attribute in the f:ajax tag. This should be listener.

Also why is there a render attribute in f:ajax? What is the "testDropDownTwoValue"? Is this a boolean or another component id? If the latter then use update attribute.
 
kranthi devarapalem
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply.

I have changed the spelling of the listener and it is not working.

in listener="#{loginBean.changeDropDownOne} will return a List that should be applied to another dropdown.

Thanks
KK
 
K. Tsang
Bartender
Posts: 3648
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then you need another drop down for testDropDownTwoValue and render this drop down when some condition is met.


 
kranthi devarapalem
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have kept the below code it did not work. control is not going to the method mentioned in listener attribute on change

<td width="42.5%" style="background-color: #DDEEF5;"><h:selectOneMenu
value="#{loginBean.dropDownValue}" itemValue="#{dropDownValue}">
<f:selectItem itemValue="****select***" />
<f:selectItems value="#{loginBean.testDropDown}"/>
<f:ajax event="change" listener="#{loginBean.changeDropDownOne}" update="testDropDownTwo" />
</h:selectOneMenu></td>
<td width="42.5%" style="background-color: #DDEEF5;">If model
users are shared with regulators please select the names(s) of the
regulator</td>
</tr>
<tr>
<td width="15%" background="red" style="background-color: #9ABDE7;">
<b>Regulator Area*</b>
</td>
<td width="42.5%" style="background-color: #DDEEF5;"><h:selectOneMenu
value="#{loginBean.dropDownTwoValue}" id="testDropDownTwoValue" render="#{loginBean.dropDownTwoValue}">
<f:selectItem itemValue="****select***" />
<f:selectItems value="#{loginBean.testDropDownTwo}" />
</h:selectOneMenu></td>
 
K. Tsang
Bartender
Posts: 3648
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe you are missing the AjaxBehaviorEvent parm in the changeDropDownOne() method.
 
kranthi devarapalem
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
do i need that ?. Actually i am new to JSF. The code of changeDropDownOne is there in the first post IF POSSIBLE could you validate that method too and correct me if i am wrong.

Thanks a Ton
 
K. Tsang
Bartender
Posts: 3648
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes you do. Have a look at the f:ajax tag here

Don't take me for granted about the attributes. That site has the other tags too.
 
Bartender
Posts: 20106
101
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

K. Tsang wrote:Yes you do. Have a look at the f:ajax tag here

Don't take me for granted about the attributes. That site has the other tags too.



No you don't. It's optional and I, for one avoid using it. That makes the listener a POJO method. Which is preferable unless you actually NEED to use that particular parameter.

I don't see an "update" attribute in the Oracle docs for the f:ajax tax. As far as I'm aware "render" is the propery attribute for re-rendering dependent elements.

 
I can't renounce my name. It's on all my stationery! And hinted in this tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!