• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JSF drop down problem

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 :


<h:outputText 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>
<h:outputText 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.
 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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()"..
 
Ranch Hand
Posts: 376
Scala Monad
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Thank you very much.
 
Gabriel Claramunt
Ranch Hand
Posts: 376
Scala Monad
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
thanks to all.
naresh.
reply
    Bookmark Topic Watch Topic
  • New Topic