This week's giveaways are in the MongoDB and Jobs Discussion forums.
We're giving away four copies of Mongo DB Applied Patterns and 4 resume reviews from Five Year Itch and have the authors/reps on-line!
See this thread and this one for details.
The moose likes JSF and the fly likes JSF drop down problem Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of Mongo DB Applied Patterns this week in the MongoDB forum
or a resume review from Five Year Itch in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » JSF
Reply Bookmark "JSF drop down problem" Watch "JSF drop down problem" New topic
Author

JSF drop down problem

Nareshkumar Kapilavai
Greenhorn

Joined: May 29, 2007
Posts: 25
Hi,
Iam very new to the JSF, i developed the page with two dropdown boxes(using selectOneMenu tags).my aim is when the user select the value of the first dropdown,the second dropdown should show the coresponding values for the first drop down selected value. for this i used valueChangeListener attribute and i wrote some methode to add coresponding values to the list for the specific selection. if i clicks on the submit button first time it is working fine and going to success page.second time it is throwing some "java.util.NoSuchElementException". i am using <managed-bean-scope>request</managed-bean-scope> in faces-conifg.xml,insted of this if i use <managed-bean-scope>session</managed-bean-scope> it is working fine but second dropdown is not refreshing. it is showing all the values.not showing only the values for the sfecific selection. my jsf code is :


<hutputText value="Project:" />
<h:selectOneMenu id="projectName" value="#{projectDetails.projectName}" styleClass="ComboBoxBig"
valueChangeListener="#{projectDetails.projectChanged}" immediate="true" onchange="submit()">
<f:selectItems value="#{projectDetails.allProjects}" />
</h:selectOneMenu>
<hutputText value="Location:" />
<h:selectOneMenu id="locationName" value="#{projectDetails.locationName}" styleClass="ComboBoxBig" >
<f:selectItems value="#{projectDetails.allLocations}" />
</h:selectOneMenu>
<h:commandButton id="submit" action="#{projectDetails.action}" value="Submit"/>

please suggest me to solve this problem. and please refer some documents on jsf to learn quickly.

Thanks&Regards!
Naresh kumar Kapilavai.
Srivatsa Katta
Ranch Hand

Joined: Aug 13, 2005
Posts: 55
Originally posted by Nareshkumar Kapilavai:

<h:selectOneMenu id="projectName" value="#{projectDetails.projectName}" styleClass="ComboBoxBig"
valueChangeListener="#{projectDetails.projectChanged}" immediate="true" onchange="submit()">
<f:selectItems value="#{projectDetails.allProjects}" />
</h:selectOneMenu>


Could you please explain what is the purpose of onchange="submit()", i could get that valueChangeListener is for filtering the values of the next drop down, but why is onchange event ??

Regards,
Srivatsa Katta
Nareshkumar Kapilavai
Greenhorn

Joined: May 29, 2007
Posts: 25
i thought it is required to add javascript event to call that listener.and i am also not sure about this. cause it is not calling that methode with out writing that onChange = "submit()"..
Gabriel Claramunt
Ranch Hand

Joined: May 26, 2007
Posts: 375
If you use "request" scope, you'll loose all the bean values each time the page is refreshed. The onChange="submit()" submits the page when the value has changed, immediate="true" skips the validations (you don't want to validate the other fields when you change the combo box).
Make sure the screen values are refreshed while on the changeListener (I'll post an example later)

BTW, feel free to check my blog (I had a paper introducing the JSF framework)


Gabriel
Software Surgeon
Nareshkumar Kapilavai
Greenhorn

Joined: May 29, 2007
Posts: 25
Hi,
Thank you very much.
Gabriel Claramunt
Ranch Hand

Joined: May 26, 2007
Posts: 375
Here is an example of parent-child selection with multiple child selection, and the list of childs is not rendered until a parent is selected...

In the JSF page:



In the backing bean:

[ June 19, 2007: Message edited by: Gabriel Claramunt ]
Nareshkumar Kapilavai
Greenhorn

Joined: May 29, 2007
Posts: 25
Hi,
thanks to all.
naresh.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: JSF drop down problem
 
Similar Threads
Value Change Listener
ValuechangeListener does not change the value
Form calling a session scoped backing bean constructor twice
Issue With selectOneMenu ValueChangeListener Not Firing
selectOneMenu VCL not firing