Java Reference
In-Depth Information
Figure 8.5: Using radio buttons for the contact's gender
We'll need a Gender property in the Contact class:
Download email_19/src/stripesbook/model/Gender.java
package stripesbook.model;
public enum Gender {
Female,
Male
}
Download email_19/src/stripesbook/model/Contact.java
package stripesbook.model;
public class Contact extends ModelBase {
/ * ... * /
private Gender gender;
/ * ... * /
public Gender getGender() {
return gender;
}
public void setGender(Gender gender) {
this .gender = gender;
}
}
The value the user enters for the gender must be either Female or Male ,
case sensitive. It's much easier and less error-prone for the user to
choose a radio button than having to type those values in a text field.
Also, radio buttons allow only one selection, making them appropriate
for the gender property.
The <s:radio> tag creates a radio button. Its name= attribute serves
an additional purpose besides containing the name of the action bean
property: it also groups buttons that have the same name. Only one
radio button from a group can be selected at a time.
 
 
Search WWH ::




Custom Search