• 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

Setting the default drop-down list value

 
Ranch Hand
Posts: 211
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have a <h:selectOneMenu> that is being populated in the backend by a managed bean. The data are coming from the database, which and I am putting inside a Collection object, which is then bounded to the <h:selectOneMenu> component, like so:



My problem is, I have a CLEAR button, that when clicked will set the value of the drop down list to a default value, say SELECT PARTNERS. So for instance, the values in the drop down list are:

SELECT PARTNER
Partner 1
Partner 2

When the current value of the drop-down is "Partner 2", and the user clicks the CLEAR button, the value will change back to "SELECT PARTNER". I am having a problem on how to this exactly in JSF. Any ideas or suggestions on how to go about this will be greatly appreciated.

Thanks in advance.
 
Ranch Hand
Posts: 536
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

all you need to do is set the partner property in "edit" bean to "SELECT PARTNER", when the clear button is pressed.
 
Eugene Abarquez
Ranch Hand
Posts: 211
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Lynette,

It worked! Thanks a lot.

I stumbled on a different solution, though it's a lot more complicated and a bit of an overkill.

I tried getting the ValueBinding of the HtmlSelectOneMenu component and setting it to null. For instance:



It seems to accomplish the same result, but yours is way simpler.
 
reply
    Bookmark Topic Watch Topic
  • New Topic