File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSF and the fly likes default values to set for radio / pulldown lists Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "default values to set for radio / pulldown lists" Watch "default values to set for radio / pulldown lists" New topic

default values to set for radio / pulldown lists

Chad Foor

Joined: Jul 03, 2007
Posts: 23

I'm having a problem trying to render this properly.

What I'd like to do - put in a default value for a set of radio buttons / select one pulldown menus. Is there a way to do this ??

I've got my JSP code like so:
<h:selectOneRadio value="#{myForm.view}" >
<f:selectItems value="#{myForm.viewItems}">

I have in the myForm bean , the following:
private static String[] ViewPoints =
"view 1",
"view 2",
"view 3",
"view 4"

public Collection getViewItems() {
if (viewItems) == null {
viewItems = new ArrayList<SelectItem>();
for (int i = 0; i < ViewPoints.length; i++)
viewItems.add(new SelectItem(ViewPoints[i]));
return viewItems;

The question is - if I can set a default value in the display like in the HTML primative declaration -
<select name="something">
<option>item one</option>
<option>item two</option>
<option selected>item three</option>

how would I mimic this default behavior in JSF ??

Appreciate any suggestions.

[ September 09, 2007: Message edited by: Chad Foor ]
Krithika Srinath
Ranch Hand

Joined: Apr 11, 2006
Posts: 52
Are you using backing bean? In that case you can set the default value in faces-config.xml as follows:

Hope this helps.
subject: default values to set for radio / pulldown lists
It's not a secret anymore!