Radio buttons are shown selected if the "property" and "value" attributes are equal.  
So, 

  <html:radio property="gender" value="m"/>Male

will display selected if the "gender" property of the form-bean is "m".  

public class MyFormBean extends ActionForm {
  private String gender;
  // getters and setters not shown for brevity
}

The typical use of radio button is -- as you have pointed out -- to allow only one 
selection in a group.  So, an extension of the above is:

  <html:radio property="gender" value="m"/>Male  
  <html:radio property="gender" value="f"/>Female

This constitutes a radio-button-group where only one of the buttons will be selected 
at any time.  When the form in which this group is contained is submitted, the value 
of the "gender" property of the form-bean will be set to "m" or "f" (if any selection 
is made).

If you have a list of yes-no questions, you can further extend this concept by having 
the appropriate properties in your form-bean

public class MyFormBean extends ActionForm {
  private String gender;
  private String status;
  // getters and setters not shown for brevity
}

  <html:radio property="gender" value="m"/>Male  
  <html:radio property="gender" value="f"/>Female

  <html:radio property="status" value="emp"/>Employed  
  <html:radio property="status" value="unemp"/>Unemployed

Hope that helps

Sri

-----Original Message-----
From: Ian Howlett [mailto:[EMAIL PROTECTED]] 
Sent: Thursday, January 30, 2003 1:13 PM
To: [EMAIL PROTECTED]
Subject: Multiple radio buttons and an ActionForm


Hi,

I have a question regarding the use of multiple radio buttons on a form. The part 
that's causing problems is taking the radio button input from the JSP page and putting 
it into an ActionForm. Then later, if the page has to be re-displayed, getting the 
data back out of the ActionForm and onto the JSP page.

The html:radio tag is not very clearly documented, and I can't find any worked 
examples.

The page I am writing will display a varying number of questions. Each question can be 
answered yes or no, but instead of using checkboxes we are using two radio buttons per 
question, one for yes and one for no. (It makes the user interface clearer).

How would the form bean be structured to contain a list of radio button results and 
how would the tag libraries render them?

Many thanks,
Mikal Todd


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to