| A thin Struts ActionForm adapter that delegates to Spring's more complete
and advanced data binder and Errors object underneath the covers to bind
to POJOs and manage rejected values.
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.
author: Keith Donald author: Juergen Hoeller since: 1.2.2 See Also: SpringBindingActionForm.expose(org.springframework.validation.Errors,javax.servlet.http.HttpServletRequest) |