You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Bailey, Shane C." <SH...@saic.com> on 2003/05/13 19:31:34 UTC

RE: Accessing an action directly with req parameter and from a fo rward?

Can you just do this:

<forward name="success" path="/AccountSummary.do" redirect="true" />



-----Original Message-----
From: otisg [mailto:otisg@ureach.com] 
Sent: Tuesday, May 13, 2003 1:18 PM
To: struts-user@jakarta.apache.org
Subject: Accessing an action directly with req parameter and from a forward?

Hello,

I am facing a problem that sounds like it would be common, but I
can't find any solutions.  A few other colleagues need to solve
the same problem, too.

Consider 3 actions:
  AccountAddEntry
  AccountAddSave
  AccountSummary

AccountAddEntry displays a blank 'Account Add' form.
AccountAddSave saves the filled up 'Account Add' form.

AccountSummary has two modes of operation:
  1. It can be called directly by the user as 
     .../AccountSummary.do?accountID=777
  2. It can be forwarded to by AccountAddSave action, after 
     AccountAddSave is done.

And that is where the problem appears.
In case 1. there is no problem.  A HREF with a link to
.../AccountSummary.do?accountID=777 works fine.

However, what about case 2?
While I can configure Actions in Struts config to get chained, I
cannot provide the request parameter needed by AccountSummary
action.

<action path="/CustomerAccountAddSave"
        type="a.b.AccountAddSaveAction"
  <forward name="success" path="/AccountSummary.do"/>
  <forward name="error"   path="/Error.do"/>
</action>

The above cannot work, because ActionSummary.do also needs the
accountID parameter, so it knows which account to show.

One solution is to have the source Action pass the data to the
receiving Action in the HttpRequest, like this, for example:

  request.setAttribute("accountID", "777");

However, that required the receiving Action to look for both
request parameter and request attribute, like this:


String acctSidStr = request.getParameter("accountID");
if (acctIDStr == null)
{
    acctDStr = (String)request.getAttribute("accountID");
}
long acctSid = Long.parseLong(accountIDStr);

There are 2 problems that:
  1. This is not very elegant, having to check 2 places for
data
  2. Because AccountAddSave 'dispatched' to AccountSummary, the
     user will not see .../AccountSummary.do in the URL.
     He will see AccountAddSave.do in the URL, but the Account
Summary will be shown.  Hitting reload will re-execute
AccountAddSave, and not AccountSummary, as an average user would
think.


How do people work around this problem?

My colleagues here are creating an additional JSP that has only
a redirect to the next Action in it.  That way they can provide
request parameters to the second method instead of passing data
in a request attribute _and_ this way they get AccountSummary in
the URL field in the browser, and a true redirect.

While this works, it is also ugly, because it introduces these
little 'redirect JSPs' which act as a redirect bridge between 2
Actions.

I would love to find a solution that allows me to do this using
only Struts config and Actions.

Is this possible?

Thank you,
Otis


________________________________________________
Get your own "800" number
Voicemail, fax, email, and a lot more
http://www.ureach.com/reg/tag

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org