Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Setting the default drop-down list value

 
Eugene Abarquez
Ranch Hand
Posts: 211
  • Mark post as helpful
  • send pies
  • 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.
 
Richard Green
Ranch Hand
Posts: 536
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic