Kazam
Aug 8th, 2007, 01:20 PM
Question
------------------
Unlike Struts where we have Action Forms or DynaActionForm, Spring allows to map between POJO's and the presentation layer. I am achieving Spring Struts integration using The Delegation Proxy [org.springframework.web.struts.DelegatingActionPro xy].
To map POJO's to presentation layer I think I can use org.springframework.web.struts.SpringBindingAction Form.
A simple example of this is given in the spring api documentation, here http://www.springframework.org/docs/api/org/springframework/web/struts/SpringBindingActionForm.html
Example definition in struts-config.xml:
<form-beans>
<form-bean name="actionForm" type="org.springframework.web.struts.SpringBindingAction Form"/>
</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");
}
The question I have is that this allows the POJO to be exposed to the presentation layer. But how do I map the POJO back to the Struts Action once a form is submitted back to a different action for instance.
Thanks, kazam.
------------------
Unlike Struts where we have Action Forms or DynaActionForm, Spring allows to map between POJO's and the presentation layer. I am achieving Spring Struts integration using The Delegation Proxy [org.springframework.web.struts.DelegatingActionPro xy].
To map POJO's to presentation layer I think I can use org.springframework.web.struts.SpringBindingAction Form.
A simple example of this is given in the spring api documentation, here http://www.springframework.org/docs/api/org/springframework/web/struts/SpringBindingActionForm.html
Example definition in struts-config.xml:
<form-beans>
<form-bean name="actionForm" type="org.springframework.web.struts.SpringBindingAction Form"/>
</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");
}
The question I have is that this allows the POJO to be exposed to the presentation layer. But how do I map the POJO back to the Struts Action once a form is submitted back to a different action for instance.
Thanks, kazam.