Introduction
In this tutorial we'll explore some of the other Struts 2 form controls. In our previous tutorials that explained how to use Struts 2 forms (Processing Forms, Form Validation, and Message Resource Files) we covered how to use the Struts 2 head, form, textfield controls and the key attribute. This tutorial will explore using the Struts 2 select, radio, checkbox, and checkboxlist form controls.
...
Code Block |
---|
| html |
---|
title | Struts 2 Select Tag |
---|
| html |
---|
|
<s:select key="personBean.sport" list="sports" />
|
...
Code Block |
---|
| html |
---|
title | HTML Created By Struts 2 Select Tag |
---|
| html |
---|
|
<tr>
<td class="tdLabel">
<label for="save_personBean_sport" class="label">Favorite sport:</label>
</td>
<td>
<select name="personBean.sport" id="save_personBean_sport">
<option value="football">football</option>
<option value="baseball">baseball</option>
<option value="basketball" selected="selected">basketball</option>
</select>
</td>
</tr>
|
...
Code Block |
---|
| html |
---|
title | Struts 2 Radio Tag |
---|
| html |
---|
|
<s:radio key="personBean.gender" list="genders" />
|
...
Code Block |
---|
| html |
---|
title | HTML Created By Struts 2 Radio Tag |
---|
| html |
---|
|
<tr>
<td class="tdLabel">
<label for="save_personBean_gender" class="label">Gender:</label></td>
<td>
<input type="radio" name="personBean.gender" id="save_personBean_gendermale" value="male"/><label for="save_personBean_gendermale">male</label>
<input type="radio" name="personBean.gender" id="save_personBean_genderfemale" value="female"/><label for="save_personBean_genderfemale">female</label>
<input type="radio" name="personBean.gender" id="save_personBean_gendernot sure" checked="checked" value="not sure"/><label for="save_personBean_gendernot sure">not sure</label>
</td>
</tr>
|
...
Code Block |
---|
| html |
---|
title | Struts 2 Select Tag Object Backed |
---|
| html |
---|
|
<s:select key="personBean.residency" list="states" listKey="stateAbbr" listValue="stateName" />
|
...
Code Block |
---|
| html |
---|
title | HTML Created By Struts 2 Select Tag |
---|
| html |
---|
|
<tr>
<td class="tdLabel">
<label for="save_personBean_residency" class="label">State resident:</label></td>
<td>
<select name="personBean.residency" id="save_personBean_residency">
<option value="AZ">Arizona</option>
<option value="CA">California</option>
<option value="FL">Florida</option>
<option value="KS" selected="selected">Kansas</option>
<option value="NY">New York</option>
</select>
</td>
</tr>
|
...
Code Block |
---|
| html |
---|
title | Struts 2 Checkbox Tag |
---|
| html |
---|
|
<s:checkbox key="personBean.over21" />
|
...
Code Block |
---|
| html |
---|
title | HTML Created By Struts 2 Checkbox Tag |
---|
| html |
---|
|
<tr>
<td valign="top" align="right">
</td>
<td valign="top" align="left">
<input type="checkbox" name="personBean.over21" value="true" checked="checked" id="save_personBean_over21"/>
<input type="hidden" id="__checkbox_save_personBean_over21" name="__checkbox_personBean.over21" value="true" /> <label for="save_personBean_over21" class="checkboxLabel">21 or older</label>
</td>
</tr>
|
...
Code Block |
---|
| html |
---|
title | Struts 2 Checkboxlist Tag |
---|
| html |
---|
|
<s:checkboxlist key="personBean.carModels" list="carModelsAvailable" />
|
...
Code Block |
---|
| html |
---|
title | HTML Created By Struts 2 Checkboxlist Tag |
---|
| html |
---|
|
<tr>
<td class="tdLabel">
<label for="save_personBean_carModels" class="label">Car models owned:</label></td>
<td>
<input type="checkbox" name="personBean.carModels" value="Ford" id="personBean.carModels-1" checked="checked"/>
<label for="personBean.carModels-1" class="checkboxLabel">Ford</label>
<input type="checkbox" name="personBean.carModels" value="Chrysler" id="personBean.carModels-2"/>
<label for="personBean.carModels-2" class="checkboxLabel">Chrysler</label>
<input type="checkbox" name="personBean.carModels" value="Toyota" id="personBean.carModels-3"/>
<label for="personBean.carModels-3" class="checkboxLabel">Toyota</label>
<input type="checkbox" name="personBean.carModels" value="Nissan" id="personBean.carModels-4" checked="checked"/>
<label for="personBean.carModels-4" class="checkboxLabel">Nissan</label>
<input type="hidden" id="__multiselect_save_personBean_carModels" name="__multiselect_personBean.carModels" value="" />
</td>
</tr>
|
...