File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 JavaScript Promises Essentials this week in the JavaScript 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
Author

default values to set for radio / pulldown lists

Chad Foor
Greenhorn

Joined: Jul 03, 2007
Posts: 23
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

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: default values to set for radio / pulldown lists