wood burning stoves 2.0*
The moose likes JSF and the fly likes How to set Default selection in h:selectOneMenu Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "How to set Default selection in h:selectOneMenu" Watch "How to set Default selection in h:selectOneMenu" New topic
Author

How to set Default selection in h:selectOneMenu

Abiodun Okusolubo
Ranch Hand

Joined: Apr 25, 2004
Posts: 72
Hello Ranchers, how can one set up a default value in a drop-down menu. For instance, if the drop down has "one", "two", "three" and "four" in the drop list. How can one programmatically set "three" as the default when the page is loaded.


SCJP, SCWCD, SCJD : in the making.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

By using the value attribute of the selectOneMenu tag.


[My Blog]
All roads lead to JavaRanch
Abiodun Okusolubo
Ranch Hand

Joined: Apr 25, 2004
Posts: 72
I don't mean how to obtain the selected value on the selectOneMenu, but to set pre-selected value on the drop-down when the page is loaded. To achive this in HTML, here is an example on how to set three as pre-selected value.
<pre>
<select name="numbers">
<option value="one">one</option>
<option value="two">two</option>
<option value="three" selected="selected">three</option>
<option value="four">four</option>
</select>
</pre>
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

This is what the value attribute is for, isn't it ?
Abiodun Okusolubo
Ranch Hand

Joined: Apr 25, 2004
Posts: 72
Thanks Chris, I've solved the issue.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to set Default selection in h:selectOneMenu