Struts newbie question on findForward

D

Darrin

OK, I'm inside the execute method of an Action class and want to do a
findForward for the name="next". Just what name="next" will be
returned?

In other words, how do I map to the right action?

Example:

public final class WizardAction extends AbstActionBase
{
private Log log = LogFactory.getLog(this.getClass().getName());

public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception
{
Locale locale = getLocale(request);
MessageResources messages = getResources();

//Create our errors collection
ActionErrors errors = new ActionErrors();

//Retrieve our form instance (derived from ActionForm)
WizardForm wizardForm = (WizardForm) form;

if (wizardForm.getCurrentStep().equals("1") &&
(wizardForm.getAction().equals(messages.getMessage("button.next"))))
{
wizardForm.setCurrentStep("2");

return (mapping.findForward("next")); <--This is the next
}


Now for a couple of the actions found in the struts-config.xml file:

<action path="/wizard"
type="cdmanager.actions.WizardAction"
name="wizardForm"
scope="request"
validate="true"
input="/wizard.jsp">
<forward name="next" path="/wizard.jsp"/>
<forward name="success" path="/wizarddone.jsp"/>
</action>

<action path="/another"
type="cdmanager.actions.AnotherAction"
name="anotherForm"
scope="request"
validate="true"
input="/another.jsp">
<forward name="next" path="/another.jsp"/>
<forward name="success" path="/anotherdone.jsp"/>
</action>

So how do I know when the findForward is done which one (another.jsp
or wizard.jsp) I will get back?

I don't see how it is mapped. I know that the type is held in the
action (cdmanager.actions.WizardAction) but what if I wanted to use
the "Another" action instead of "Wizard" action?

Just how does the mapping occur?

THANKS!!!!!!
 
W

Wendy S

Darrin said:
OK, I'm inside the execute method of an Action class and want to do a
findForward for the name="next". Just what name="next" will be
returned?

The one that comes from the ActionMapping that got you where you are now.
In your case, you're in WizardAction, which is this one:
<action path="/wizard"
type="cdmanager.actions.WizardAction"
name="wizardForm"
scope="request"
validate="true"
input="/wizard.jsp">
<forward name="next" path="/wizard.jsp"/>
<forward name="success" path="/wizarddone.jsp"/>
</action>

So, within WizardAction, when you say mapping.findForward( "next" ) it looks
at that snippet of XML I quoted above, finds the 'next' forward, and sends
you off to /wizard.jsp.
Just how does the mapping occur?

When Struts starts up, it parses the struts-config.xml file. Each <action>
tag is turned into an ActionMapping object. Take a look at the
ActionMapping (& parent ActionConfig) javadocs and see if it makes things
any clearer.

http://jakarta.apache.org/struts/api/org/apache/struts/action/ActionMapping.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,150
Latest member
MakersCBDReviews
Top