Win a copy of Pragmatic AI this week in the Artificial Intelligence forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

how do i make a radio button to be checked when a page loads up?  RSS feed

 
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all:
as you know, in html, if I want the radio button to be the checked when a page loads up, i'd do

<input type ="radio" name="r1" checked/>

how do i do that in struts? I don't think there is a checked field associated with
<html:radio> is there? please let me know...

thanks
 
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The way I did it was to pass a value to the .jsp through a bean with a pre-choosen value in there.

Following are code snippets

Action.java


webpage.jsp


When the page loads, the radio which matches the value will be highlighted.

As far as having it on without a javaBean, I don't know of a way to do that.
 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think, javascript can be one of the solution for selecting a radio button.
 
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't need any special tricks. Something like this works for prepop:

<html:radio property="gender" value="male">Male</html:radio>
<html:radio property="gender" value="female">Female</html:radio>

ActionForm needs a getter/setter for gender (as usual).

If you wanted it to default to Male at the beginning, make "male" the value of String gender in your ActionForm.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Either through javascript or with the help of ActionForm's setter method before loading the page can do this.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!