wood burning stoves 2.0*
The moose likes JSF and the fly likes Setting the default drop-down list value Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Setting the default drop-down list value" Watch "Setting the default drop-down list value" New topic

Setting the default drop-down list value

Eugene Abarquez
Ranch Hand

Joined: May 18, 2006
Posts: 211

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:

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.

There's so much to learn in this industry, and not everybody has the necessary interest.
Richard Green
Ranch Hand

Joined: Aug 25, 2005
Posts: 536

all you need to do is set the partner property in "edit" bean to "SELECT PARTNER", when the clear button is pressed.

MCSD, SCJP, SCWCD, SCBCD, SCJD (in progress - URLybird 1.2.1)
Eugene Abarquez
Ranch Hand

Joined: May 18, 2006
Posts: 211
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.
I agree. Here's the link: http://aspose.com/file-tools
subject: Setting the default drop-down list value
Similar Threads
selected value through select items
Using Operators in Drop down
Stuck with AJAX implementation on form reload
Setting bean value problem
Drop down list value