Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

default values to set for radio / pulldown lists

 
Chad Foor
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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}">
</h:selectOneRadio>

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>
</select>

how would I mimic this default behavior in JSF ??

Appreciate any suggestions.

Thanks,
Chad
[ September 09, 2007: Message edited by: Chad Foor ]
 
Krithika Srinath
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you using backing bean? In that case you can set the default value in faces-config.xml as follows:



Hope this helps.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic