Home > Guides > Core Developers Guide > Model Driven |
Struts 2 does not have "forms" like Struts 1 did. In Struts 2 request parameters are bound directly to fields in the actions class, and this class is placed on top of the stack when the action is executed.
If an action class implements the interface com.opensymphony.xwork2.ModelDriven
then it needs to return an object from the getModel()
method. Struts will then populate the fields of this object with the request parameters, and this object will be placed on top of the stack once the action is executed. Validation will also be performed on this model object, instead of the action.
To use ModelDriven
actions, make sure that the Model Driven Interceptor is applied to your action. This interceptor is part of the default interceptor stack defaultStack
so it is applied to all actions by default.
Action class:
Gangster class (model):
JSP for creating a Gangster: