You can change the current page in other ways. For example, returning the
page name in your listener method, or an IPage object.
But if you have to stop the current request lifecycle and go to another page
(for example because of a security issue) then you throw that exception. You
don't want to render the current page, because you validated some thing, so
I think it's a good idea to use an exception for this cases.
On 2/26/06, Andrea Chiumenti <[EMAIL PROTECTED]> wrote:
>
> James Carman wrote:
>
> >Here's how I handle page redirects...
> >
> >1. Create a ComponentUtils service interface/implementation...
> >
> >public interface ComponentUtils
> >{
> > public void redirectToPage( String pageName );
> >
> > public void redirectToPage( IPage page );
> >}
> >
> >public class ComponentUtilsImpl implements ComponentUtils
> >{
> > private IEngineService pageService;
> >
> > public void redirectToPage( String pageName )
> > {
> > throw new RedirectException( pageService.getLink( false, pageName
> >).getURL() );
> > }
> >
> > public void redirectToPage( IPage page )
> > {
> > redirectToPage( page.getPageName() );
> > }
> >
> > public void setPageService( IEngineService pageService )
> > {
> > this.pageService = pageService;
> > }
> >}
> >
> >
> >2. In your hivemodule.xml file...
> >
> ><service-point id="ComponentUtils"
> >interface="com.myco.web.service.ComponentUtils">
> > <invoke-factory>
> > <construct class="
> com.myco.web.service.impl.ComponentUtilsImpl">
> > <set-object property="pageService"
> >value="service:tapestry.services.Page"/>
> > </construct>
> > </invoke-factory>
> ></service-point>
> >
> >3. Then, in your page/component, just inject the ComponentUtils
> service...
> >
> >@InjectObject("service:myco.ComponentUtils")
> >public abstract ComponentUtils getComponentUtils();
> >
> >4. Then use it!
> >
> >public void someListenerMethod()
> >{
> > // Do something.
> > getComponentUtils().redirectToPage( "Home" );
> >}
> >
> >
> >-----Original Message-----
> >From: Andrea Chiumenti [mailto:[EMAIL PROTECTED]
> >Sent: Saturday, February 25, 2006 10:54 AM
> >To: Tapestry users
> >Subject: Page rediraction problem
> >
> >Hello , I'm trying to redirect users to the Home page when they are not
> >in role, but this doesn't happen and I don't kwno why, since the
> >debugger checks correctly, so it must be my code!
> >
> >here it is what I'm trying to execute.
> >
> >public void renderPage(IMarkupWriter writer, IRequestCycle cycle) {
> >
> > JFlyPrincipal principal = getPrincipal();
> > if ( (principal == null) ||
> >(!principal.isUserInRole(getRoles())) ) {
> > cycle.activate("Home");
> > }
> > super.renderPage(writer, cycle);
> >
> > }
> >
> >Could someone help me please ?
> >
> >Regards,
> >kiuma
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: [EMAIL PROTECTED]
> >For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: [EMAIL PROTECTED]
> >For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
> >
> Thank you it perfectly worked. But I wonder why to throw an exception to
> go to another page (yes in my own case it was right to throw an exc.).
> For example if I change user data, after post I would like to see his
> card, why should I use an exception to go to that page, since it's not a
> real exception?
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>