You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Kurt Zoglmann <zo...@yahoo.com> on 2004/09/20 22:17:00 UTC
Better alternative to RedirectException?
After some trial and error I got something working, but it doesn't seem
like a good solution. I have a page that contains several components.
In a specific situation determined by the components, I would like the
components to discard the page (causing all persistent values to be
thrown away) and for the page to refresh to itself.
In the documentation for PageRedirectException it says that it is
"thrown by a component or IEngineService that wishes to force the
application to a particular page." However, when I throw a
PageRedirectionException in
BaseComponent.prepareForRender(IRequestCycle) the exception is only
caught by Tapestry to display the stack trace as a webpage to the user.
The following code works, but it seems like an ugly hack. Is there a
more appropriate way of doing this?
public abstract class SomeComponent extends BaseComponent
protected void prepareForRender(IRequestCycle cycle) {
if(--condition needing to reset and refresh page--) {
String pageName = cycle.getPage().getPageName();
cycle.discardPage(pageName);
RequestContext context = cycle.getRequestContext();
String URL =
"http:/
/"+context.getServerName()+":"+context.getServerPort()+context.getReques
tURI()+"?service=page/"+pageName;
throw new RedirectException(URL);
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Re: Better alternative to RedirectException?
Posted by Paul Ferraro <pm...@columbia.edu>.
I posted some code addressing this a while back...
http://www.caddr.com/macho/archives/tapestry-users/2004-3/4619.html
Paul
Kurt Zoglmann wrote:
> After some trial and error I got something working, but it doesn't
> seem like a good solution. I have a page that contains several
> components. In a specific situation determined by the components, I
> would like the components to discard the page (causing all persistent
> values to be thrown away) and for the page to refresh to itself.
>
> In the documentation for PageRedirectException it says that it is
> "thrown by a component or IEngineService that wishes to force the
> application to a particular page." However, when I throw a
> PageRedirectionException in
> BaseComponent.prepareForRender(IRequestCycle) the exception is only
> caught by Tapestry to display the stack trace as a webpage to the user.
>
> The following code works, but it seems like an ugly hack. Is there a
> more appropriate way of doing this?
>
> public abstract class SomeComponent extends BaseComponent
>
> protected void prepareForRender(IRequestCycle cycle) {
> if(--condition needing to reset and refresh page--) {
> String pageName = cycle.getPage().getPageName();
> cycle.discardPage(pageName);
> RequestContext context = cycle.getRequestContext();
> String URL = "http:/
> /"+context.getServerName()+":"+context.getServerPort()+context.getReques
> tURI()+"?service=page/"+pageName;
> throw new RedirectException(URL);
> }
> }
>
> }
>
>
> ---------------------------------------------------------------------
> 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