Assuming a simple configuration in struts-config like the following:
<action path="/action1"
type="...."
name="form1"
scope="...">
<forward name="success" path="/action2.do"/>
</action>
<action path="/action2"
type="...."
name="form2"
scope="...">
...
</action>
To forward to your second action, you just use return mapping.findForward("success");
and the flow will be forwarded to the second action. Assuming you have some configs like the following for each ActionForm:
<form-beans>
<form-bean name="form1" type="..." />
<form-bean name="form2" type="..." />
</form-beans>
then what you want is to get your hand on form2
and fill it with data before doing the forward.
You can off course do that since each form (be it form1
or form2
) are bounded to the specified scope with the specified name, but that will be interfering with Struts normal flow and it is a bad practice (you must really know how Struts works before stepping in and stealing the show). That's is why I won't tell you how to do it.
What I recommend you to do instead is to decouple as much as you can the two actions. Each action will do its thing, no action will depend on data being pre-filled by another action.
To do that, move your "magic" code in your second action and do the operations once you are there. If you only need to do the operations in action 2 if you come from action 1 then you can add a flag to the configuration:
<forward name="success" path="/action2.do?theFlag"/>
and test for that in action 2 (request.getParameter("theFlag") != null
for example). This way, you have the two actions tied only by the flag.
One other thing you can do is use DispatchAction classes. This is a collection of execute methods that could all share the same form so you forward from one method to the other without having multiple forms to manage.
EDIT: Based on your comment: "...my new feature, needs to execute some logic prior to it and only if successful go on to execute the "original' action." do you mean you just need something like this:
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception {
ActionForward forwardPage = mapping.findForward("success");
// Some Code....
boolean isSuccess = runLogicAndReturnStatus();
if (isSuccess) {
return forwardPage;
} else {
return mapping.findForward("error"); // or return to the same page (input page)
}
}
If that is it, why do you need to create a new ActionForm instance and have it associated with the forwarded action?