• Post Reply Bookmark Topic Watch Topic
  • New Topic

JSF drop down problem  RSS feed

 
Nareshkumar Kapilavai
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 375
Monad Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)
 
Nareshkumar Kapilavai
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Thank you very much.
 
Gabriel Claramunt
Ranch Hand
Posts: 375
Monad Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
thanks to all.
naresh.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!