Hi All,
I'm having trouble forwarding one action to another and sending
properties on through. Let's say I have two actions, "SomeAction" and
"SomeOtherAction", and two form beans, "SomeForm" (with property
"someProp") and "SomeOtherForm" (with property "someOtherProp"). If I
want one action to go to the other, here's how I do it:
---[ struts-config.xml ]---
<form-beans>
<form-bean name="someForm" type="mypkg.SomeForm" />
<form-bean name="someOtherForm" type="mypkg.SomeOtherForm" />
</form-beans>
<action path="/someAction" type="mypkg.SomeAction" name="someForm"
scope="request" validate="false">
<forward name="success" path="/someOtherAction.do" />
</action>
<action path="/someOtherAction" type="mypkg.SomeOtherAction"
name="someOtherForm" scope="request" validate="false">
<forward name="success" path="page.main" />
<forward name="failure" path="somewhere.bad" />
</action>
---------------------------
Having fun so far? Good!
---[ SomeAction.java ]---
public class SomeAction extends Action
{
public ActionForward execute( ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response )
throws Exception
{
SomeForm theForm = (SomeForm)form;
SomeOtherForm newForm = new SomeOtherForm();
newForm.setSomeOtherProp( theForm.getSomeProp() );
request.setAttribute( "someOtherForm", newForm );
return mapping.findForward( "success" );
}
}
-------------------------
Almost done...
---[ SomeOtherAction.java ]---
public class SomeOtherAction extends Action
{
public Washroom execute( ... ) throws AFit
{
SomeOtherForm theForm = (SomeOtherForm)form;
if ( theForm.getSomeOtherProp().equals( "" ) )
{
return mapping.findForward( "failure" );
}
else
{
return mapping.findForward( "success" );
}
}
}
-----------------------------
The "failure" forward always gets hit because someOtherProp is always
null. The form gets reset() after I prepopulate someOtherForm and loses
the value I set! So I suspect the typical response to this might be
"well, duh," but this is how I've taken to passing parameters across
actions. Looks like I've been fooling myself with my other Action
classes because most of the properties have the same name, so the
reset() doesn't matter! My questions are:
1. Am I chaining the actions together properly (with the path="/blah.do"?)
2. Is this the appropriate way to prepopulate ActionForms?
3. Did anyone see my action throw a fit in the public washroom?
Thanks,
Scott
(It's been a long day, I suspect my silliness in this public post will
come back to haunt me in a few decades)
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]