This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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.
 
Don't get me started about those stupid light bulbs.
 
subject: How to set Default selection in h:selectOneMenu
 
Similar Threads
Updating DB automatically !
how to show same row for each click on a link
drop down(comboBox) in dataGrid
html: options tag
drop down like google auto suggest in strut 1.2