wood burning stoves 2.0*
The moose likes JSF and the fly likes How to select one Radio button by default. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "How to select one Radio button by default." Watch "How to select one Radio button by default." New topic
Author

How to select one Radio button by default.

vinutha
Greenhorn

Joined: Nov 29, 2006
Posts: 29
This is the code for Radio buttons,
When i run my application, "Button1" should be selected automatically.

<h:selectOneRadio required="true" >
<f:selectItem itemValue="Button1" itemLabel="Button1"/>
<f:selectItem itemValue="Button2" itemLabel="Button2" /> </h:selectOneRadio>

so, how to select one Radio button defaultly.

Thanks,
Vinutha.
Manuel Palacio
Ranch Hand

Joined: Oct 16, 2000
Posts: 45
You have to use itemValue like:

for the button that should be selected by default. The other one should be false then.


<a href="http://www.newinstance.net" target="_blank" rel="nofollow">http://www.newinstance.net</a>
vinutha
Greenhorn

Joined: Nov 29, 2006
Posts: 29
Hi Manuel,

I made change like this by adding true to itemValue,
<h:selectOneRadio required="true" >
<f:selectItem itemValue="true" itemLabel="Button1"/>
<f:selectItem itemValue="false" itemLabel="Button2" />
</h:selectOneRadio>

but, its not changing.

Thanks,
Vinutha
Remko Strating
Ranch Hand

Joined: Dec 28, 2006
Posts: 893
In your example code I miss the value of the backingbean within your
<h:selectOneRadio /> Tag.

Normally the option is chosen which is the value of your backing bean.
You can give this value your wanted default value.

I hope this helps.


Remko (My website)
SCJP 1.5, SCWCD 1.4, SCDJWS 1.4, SCBCD 1.5, ITIL(Manager), Prince2(Practitioner), Reading/ gaining experience for SCEA,
Andres Quinones
Ranch Hand

Joined: Oct 09, 2006
Posts: 57
Originally posted by vinutha:
Hi Manuel,

I made change like this by adding true to itemValue,
<h:selectOneRadio required="true" >
<f:selectItem itemValue="true" itemLabel="Button1"/>
<f:selectItem itemValue="false" itemLabel="Button2" />
</h:selectOneRadio>

but, its not changing.

Thanks,
Vinutha


Hi Vinutha, you forget the value attribute for the selectOneRadio like this:
<h:selectOneRadio required="true" value="#{MyBean.valueAttr}" >
<f:selectItem itemValue="true" itemLabel="Button1"/>
<f:selectItem itemValue="false" itemLabel="Button2" />
</h:selectOneRadio>

so if you put true or false to the valueAttr in your Bean the radio will appear selected.

Hope this helps
vinutha
Greenhorn

Joined: Nov 29, 2006
Posts: 29
Hi Andres,

Thanks for your reply.
Its working now.

Thanks a lot.
Thanks,
Vinutha.
Bert Bates
author
Sheriff

Joined: Oct 14, 2002
Posts: 8803
    
    5
hi vinutha,

please update your display name to match the avaRanch policy - include both your first and last names.

Thanks, and welcome to the ranch

Bert


Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to select one Radio button by default.
 
Similar Threads
How to create default value for radio button
Adding space between Radio button and Label
selectOneRadio problem
Radio
How to make one of the Radio button default selected