You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Eric Jain <Er...@isb-sib.ch> on 2006/01/07 12:51:09 UTC
How to forward from one action to another, with modified parameters?
If a request for
/retrieve.do?id=42
fails (e.g. couldn't find item in database), I'd like to say
request.setStatus(HttpServletResponse.SC_NOT_FOUND);
request.setAttribute("warning", "Not your lucky day.");
and forward (not redirect) the request to
/search.do?query=42
Can this behavior be accomplishing with Struts? Currently I'm using
request.getRequestDispatcher(...).forward(...) with a modified
HttpServletRequest, but there must be a better way (TM)...
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: How to forward from one action to another, with modified parameters?
Posted by Rick Reumann <st...@reumann.net>.
Dakota Jack wrote the following on 1/7/2006 10:09 AM:
> In my opinion, Eric, this is a bad solution. There are lots of reasons this
> is bad. Rather than go through them, I would suggest you just add the logic
> in /search.do?query=42 at the point you get the failure form
> /retrieve.do?id=42.
I agree with Jack here. The code to get back your Collection of objects
based on "id 42" should be about one line. Then maybe another to
populate the request so you aren't really saving maybe lines of code
forwarding to another action. So for example if whatever action is
processing your /retrieve.do?id=42 simply do something like...
retrieveAction(..) -->
String forwardName = "success";
Item item = service.getItemFromDB( 42 );
if ( item == null ) {
Collection items = service.performSearch( 42 );
request.setAttribute("items", items );
forwardName = "itemNotFound";
}else {
//probably put item in scope
request.setAttribute("item", item );
}
return (mapping.findForward(forwardName ));
--
Rick
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: How to forward from one action to another, with modified parameters?
Posted by Dakota Jack <da...@gmail.com>.
In my opinion, Eric, this is a bad solution. There are lots of reasons this
is bad. Rather than go through them, I would suggest you just add the logic
in /search.do?query=42 at the point you get the failure form
/retrieve.do?id=42.
On 1/7/06, Eric Jain <Er...@isb-sib.ch> wrote:
>
> If a request for
>
> /retrieve.do?id=42
>
> fails (e.g. couldn't find item in database), I'd like to say
>
> request.setStatus(HttpServletResponse.SC_NOT_FOUND);
> request.setAttribute("warning", "Not your lucky day.");
>
> and forward (not redirect) the request to
>
> /search.do?query=42
>
> Can this behavior be accomplishing with Struts? Currently I'm using
> request.getRequestDispatcher(...).forward(...) with a modified
> HttpServletRequest, but there must be a better way (TM)...
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
--
"You can lead a horse to water but you cannot make it float on its back."
~Dakota Jack~