• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

How to select one Radio button by default.

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 893
Tomcat Server Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Andres,

Thanks for your reply.
Its working now.

Thanks a lot.
Thanks,
Vinutha.
 
author
Posts: 9046
21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic