• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Getting Selection from selectOneMenu

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
i am new to JSF and this forum, so here is my first question. I have a JSF page with a selectOneMenu on it, where the names of the EJB managed entities (retrieved from DB) are displayed. The rest of the page are mostly text fields used to edit the properties of the business entity currently selected. These fields need to be refreshed when the user first selects a new entity in the selectOneMenu and then clicks the "Ok" button. I populate the combo with a Collection of SelectItems which have my entities as value and their names as label. On submitting the form with a button how do i get the selection from the selectOneMenu? My entities are not identified by their names, that is why i need not only to get the string (value?) from the selectOneMenu, but the real object stored in the SelectItem. That is i would like to see something like this:



this code i only the product of my imagination with everything made up, but it would be great if someone tells me how i do something like this in reality.

As an alternative i tried to attach a listener to the selectOneMenu and use it to set some temporary variable in the managed bean which is then read when the "Ok" button is pressed, but first this causes the page to reload every time i change selection and second, i can't make the listener work (tried both implementig the ValueChangeListener interface and specifying a conrete method in my bean). Further, i don't fully understand the function if the "value" attribute in the <h:selectOneMenu> since there is also a "value" attribute in the <f:selectItems> element. Do i need the first one if i specify the second? Is there a way to set the selection in the selectOneMenu to a specific SelectItem? Something like selectOneMenu.setSelectionIndex(5)?

Thank you for your help.
 
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
About using objects in h:selectOneMenu: use a converter or a backing map. Also see the examples here: http://balusc.blogspot.com/2007/09/objects-in-hselectonemenu.html

About using the value attribute: use it to get or set the selected item in the bean.
 
He puts the "turd" in "saturday". Speaking of which, have you smelled this tiny ad?
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic