@Deprecated public class SpringBindingActionForm extends org.apache.struts.action.ActionForm
Exposes Spring-managed errors to the standard Struts view tags, through exposing a corresponding Struts ActionMessages object as request attribute. Also exposes current field values in a Struts-compliant fashion, including rejected values (which Spring's binding keeps even for non-String fields).
Consequently, Struts views can be written in a completely traditional
fashion (with standard html:form
, html:errors
, etc),
seamlessly accessing a Spring-bound POJO form object underneath.
Note this ActionForm is designed explicitly for use in request scope.
It expects to receive an expose
call from the Action, passing
in the Errors object to expose plus the current HttpServletRequest.
Example definition in struts-config.xml
:
<form-beans> <form-bean name="actionForm" type="org.springframework.web.struts.SpringBindingActionForm"/> </form-beans>Example code in a custom Struts
Action
:
public ActionForward execute(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) throws Exception { SpringBindingActionForm form = (SpringBindingActionForm) actionForm; MyPojoBean bean = ...; ServletRequestDataBinder binder = new ServletRequestDataBinder(bean, "myPojo"); binder.bind(request); form.expose(binder.getBindingResult(), request); return actionMapping.findForward("success"); }This class is compatible with both Struts 1.2.x and Struts 1.1. On Struts 1.2, default messages registered with Spring binding errors are exposed when none of the error codes could be resolved. On Struts 1.1, this is not possible due to a limitation in the Struts message facility; hence, we expose the plain default error code there.
expose(org.springframework.validation.Errors, javax.servlet.http.HttpServletRequest)
,
Serialized FormConstructor and Description |
---|
SpringBindingActionForm()
Deprecated.
|
Modifier and Type | Method and Description |
---|---|
void |
expose(Errors errors,
HttpServletRequest request)
Deprecated.
Set the Errors object that this SpringBindingActionForm is supposed
to wrap.
|
public void expose(Errors errors, HttpServletRequest request)
errors
- the Spring Errors object to wrap, usually taken from
a DataBinder that has been used for populating a POJO form objectrequest
- the HttpServletRequest to retrieve the attributes fromDataBinder.getBindingResult()