You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Andrea Chiumenti <ki...@wingstech.com> on 2006/02/25 16:53:50 UTC

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: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: Page rediraction problem

Posted by Pablo Ruggia <pr...@gmail.com>.
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 <ki...@wingstech.com> 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:kiuma.tapestry@wingstech.com]
> >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: 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
> >
> >
> >
> 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: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>

Re: Page rediraction problem

Posted by Andrea Chiumenti <ki...@wingstech.com>.
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:kiuma.tapestry@wingstech.com] 
>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: 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
>
>  
>
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: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


RE: Page rediraction problem

Posted by James Carman <ja...@carmanconsulting.com>.
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:kiuma.tapestry@wingstech.com] 
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: 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


RE: Page rediraction problem

Posted by James Carman <ja...@carmanconsulting.com>.
Sorry, don't know what combination of keys I hit in Outlook, but this was
sent prematurely.   

-----Original Message-----
From: James Carman [mailto:james@carmanconsulting.com] 
Sent: Saturday, February 25, 2006 10:56 AM
To: 'Tapestry users'
Subject: RE: Page rediraction problem

Here's what I did...

<service-point 
  id="ComponentUtils"
interface="com.martialware.web.service.ComponentUtils">
        <invoke-factory>
            <construct
class="com.martialware.web.service.impl.ComponentUtilsImpl">
                <set-object property="pageService"
value="service:tapestry.services.Page"/>
            </construct>
        </invoke-factory>
</service-point>

-----Original Message-----
From: Andrea Chiumenti [mailto:kiuma.tapestry@wingstech.com] 
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: 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



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


RE: Page rediraction problem

Posted by James Carman <ja...@carmanconsulting.com>.
Here's what I did...

<service-point 
  id="ComponentUtils"
interface="com.martialware.web.service.ComponentUtils">
        <invoke-factory>
            <construct
class="com.martialware.web.service.impl.ComponentUtilsImpl">
                <set-object property="pageService"
value="service:tapestry.services.Page"/>
            </construct>
        </invoke-factory>
</service-point>

-----Original Message-----
From: Andrea Chiumenti [mailto:kiuma.tapestry@wingstech.com] 
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: 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