You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Patrick Casey <pa...@adelphia.net> on 2005/05/13 19:32:05 UTC

Pass Parameters with a PageRedirectException

	
	Hi Folks,

	I'm trying to implement the POST->Redirect->GET model inside of my
Tapestry app. I've done it before in most things I've written so the users
don't get those nasty scary "This Page contains POST data" when they push
refresh after a post. In this case though I'm trying to do it within
Tapestry (without driving a knife through the framework and just grabbing
ahold of the HTTPServeletRequest and redirecting there), and I'm a bit
stumped.

	I'm at a point in my code where I know:

	1) I need to redirect to a page named "genericlist".
	2) I need to pass said page a set of parameters (so it knows what to
list).

	I can redirect with a simple:

	Throw new PageRedirectException("genericList");

	But that doesn't let me pass along a set of parameters so that the
target page knows what to do.

	Is there a way I can pass a parameter array along with a
PageRedirectException? 

	--- Pat



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


Re: Pass Parameters with a PageRedirectException

Posted by Paul Ferraro <pm...@columbia.edu>.
To implement POST->Redirect->GET, you need to use RedirectException, NOT 
PageRedirectException.
Throwing PageRedirectException simply interrupts the current render 
cycle and activates the specified page within the same request.
To generate the url required for RedirectException you will need to use 
the appropriate engine service.

Because it the code required to generate urls for RedirectException 
requires so much tedious logic, I've created a simple extension to the 
RedirectException to ease the construction of urls for the Page, 
External, and Direct services (see below).  I posted this code well over 
a year ago, but at the time there was some disagreement among the 
developers (I was not yet one) regarding its utility.  Now that I am 
one, I'll see that 4.0 addresses the current shortcomings of 
RedirectException.  I would also love to rename PageRedirectException at 
some point so that it ceases to become a point of confusion...

Paul


public class RedirectException extends org.apache.tapestry.RedirectException
{
    private static final long serialVersionUID = 4049918285694842678L;

    public RedirectException(String url)
    {
        super(url);
    }
   
    public RedirectException(ILink link)
    {
        this(link.getURL());
    }
   
    public RedirectException(IRequestCycle cycle, String page)
    {
        
this(cycle.getEngine().getService(Tapestry.PAGE_SERVICE).getLink(cycle, 
cycle.getPage(), new String[] { page }));
    }
  
    public RedirectException(IRequestCycle cycle, String page, Object 
parameters)
    {
        
this(cycle.getEngine().getService(Tapestry.EXTERNAL_SERVICE).getLink(cycle, 
cycle.getPage(), getServiceParameters(page, parameters)));
    }
  
    public RedirectException(IRequestCycle cycle, IDirect direct, Object 
parameters)
    {
        
this(cycle.getEngine().getService(Tapestry.DIRECT_SERVICE).getLink(cycle, 
direct, DirectLink.constructServiceParameters(parameters)));
    }

    private static Object[] getServiceParameters(String targetPage, 
Object parameter)
    {
        Object[] pageParameters = 
DirectLink.constructServiceParameters(parameter);
        if (pageParameters == null)
        {  
            return new Object[] { targetPage };
        }
        Object[] parameters = new Object[pageParameters.length + 1];
        parameters[0] = targetPage;
        System.arraycopy(pageParameters, 0, parameters, 1, 
pageParameters.length);
        return parameters;
    }
}

Patrick Casey wrote:

>	
>	Hi Folks,
>
>	I'm trying to implement the POST->Redirect->GET model inside of my
>Tapestry app. I've done it before in most things I've written so the users
>don't get those nasty scary "This Page contains POST data" when they push
>refresh after a post. In this case though I'm trying to do it within
>Tapestry (without driving a knife through the framework and just grabbing
>ahold of the HTTPServeletRequest and redirecting there), and I'm a bit
>stumped.
>
>	I'm at a point in my code where I know:
>
>	1) I need to redirect to a page named "genericlist".
>	2) I need to pass said page a set of parameters (so it knows what to
>list).
>
>	I can redirect with a simple:
>
>	Throw new PageRedirectException("genericList");
>
>	But that doesn't let me pass along a set of parameters so that the
>target page knows what to do.
>
>	Is there a way I can pass a parameter array along with a
>PageRedirectException? 
>
>	--- Pat
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>  
>


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