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

How to select one Radio button by default.

 
vinutha
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have to use itemValue like:

for the button that should be selected by default. The other one should be false then.
 
vinutha
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 893
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Andres Quinones
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Andres,

Thanks for your reply.
Its working now.

Thanks a lot.
Thanks,
Vinutha.
 
Bert Bates
author
Sheriff
Posts: 8900
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic