Java Reference
In-Depth Information
Figure 15.8: Car models are populated after selecting a make.
package
stripesbook.action;
public class
PartialFormActionBean
extends
BaseActionBean {
private static final
String VIEW = "/WEB-INF/jsp/cars.jsp";
private static final
String RESULT = "/WEB-INF/jsp/partial_form.jsp";
private
Cars cars =
new
Cars();
public
String make;
private
List<String> models;
@DefaultHandler
public
Resolution view() {
return new
ForwardResolution(VIEW);
}
public
Cars getCars() {
return
cars;
}
public
List<String> getModels() {
return
models;
}
public
Resolution updateModels() {
models = cars.get(make);
return new
ForwardResolution(RESULT);
}
}
The form contains the select box with the car makes and a
'model-
Choices'
placeholder for the car models:
<s:form beanclass="stripesbook.action.PartialFormActionBean">
Make:
<s:select name="make" onchange="updateModels(this);">
<s:option value="" label="..."/>
<s:options-map map="${actionBean.cars}" label="key"/>
</s:select>
Model:
<span id="modelChoices"><s:select name="models"/></span>
</s:form>
Search WWH ::
Custom Search