java.lang.Object | ||
↳ | ActionForm | |
↳ | org.springframework.web.struts.SpringBindingActionForm |
This class is deprecated.
as of Spring 3.0
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.
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Set the Errors object that this SpringBindingActionForm is supposed
to wrap.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
|
Set the Errors object that this SpringBindingActionForm is supposed to wrap. The contained field values and errors will be exposed to the view, accessible through Struts standard tags.
errors | the Spring Errors object to wrap, usually taken from a DataBinder that has been used for populating a POJO form object |
---|---|
request | the HttpServletRequest to retrieve the attributes from |