You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Yves Sy <yv...@gmail.com> on 2005/03/10 03:48:17 UTC

Forwarding to a page on pageBeginRender

Hello,

I'm using pageBeginRender to check for a condition, which if true,
should forward the user to another page:

public void pageBeginRender(PageEvent e) {
        MyVisit visit = (MyVisit) getEngine().getVisit();
        if (visit != null && visit.isAuthenticated()) {
            throw new PageRedirectException("search");
        }
}

The above code works fine now but I still have some questions. One is,
why doesn't the following code work instead:

public void pageBeginRender(PageEvent e) {
        MyVisit visit = (MyVisit) getEngine().getVisit();
        if (visit != null && visit.isAuthenticated()) {
            IRequestCycle cycle = e.getRequestCycle();
            cycle.activate("search");
        }
}

I'm asking this because in ordinary servlets, you can either redirect
or forward to another page whereas here, it seems we can only
redirect.

...OR am I using the correct method to do this (pageBeginRender)?
Maybe there's another place where things like these are supposed to be
done...?

Finally, what's the difference between pageBeginRender and
beginPageRender? Its a bit confusing :o(

Just want to improve my understanding of the framework :o)

Thanks,
-Yves-


-- 
A bus station is where a bus stops. A train station is where a train
stops. On my desk I have a work station...

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


Re: Forwarding to a page on pageBeginRender

Posted by Serge Ivanchenko <sg...@yahoo.com>.
It's better to throw PageRedirectException exception in function validate,
something like this:


    public void validate(IRequestCycle cycle)
    {
        Visit visit = (Visit)this.getVisit();

        if (!visit.isLoggedIn())
        {
            // set error
            visit.signOut();
            cycle.getEngine().setVisit(null);
           
            throw new PageRedirectException("Home");
        }
        super.validate(cycle);
    }



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


Re: Forwarding to a page on pageBeginRender

Posted by Yves Sy <yv...@gmail.com>.
Sounds interesting but I just wonder which one is the more
conventional way of doing it. Anyway it works and its not messy so I'm
cool with that.

Thanks!


On Thu, 10 Mar 2005 09:56:31 +0000, Richard Kirby <rb...@capdm.com> wrote:
> 
> On 10 Mar 2005, at 02:48, Yves Sy wrote:
> 
> > Hello,
> >
> > I'm using pageBeginRender to check for a condition, which if true,
> > should forward the user to another page:
> >
> > public void pageBeginRender(PageEvent e) {
> >         MyVisit visit = (MyVisit) getEngine().getVisit();
> >         if (visit != null && visit.isAuthenticated()) {
> >             throw new PageRedirectException("search");
> >         }
> > }
> >
> > The above code works fine now but I still have some questions. One is,
> > why doesn't the following code work instead:
> >
> > public void pageBeginRender(PageEvent e) {
> >         MyVisit visit = (MyVisit) getEngine().getVisit();
> >         if (visit != null && visit.isAuthenticated()) {
> >             IRequestCycle cycle = e.getRequestCycle();
> >             cycle.activate("search");
> >         }
> > }
> 
> This doesn't work, because by the time pageBeginRender is called, the
> RequestCycle has already been used to determine the activated page, so
> cycle.activate no longer has an effect. That is why the
> PageRedirectException is needed, as it causes the page rendering to be
> aborted and restarted. Note that the PageRedirectException is actually
> handled internally by Tapestry, and is not a client browser redirect.
> 
> >
> > I'm asking this because in ordinary servlets, you can either redirect
> > or forward to another page whereas here, it seems we can only
> > redirect.
> >
> > ...OR am I using the correct method to do this (pageBeginRender)?
> > Maybe there's another place where things like these are supposed to be
> > done...?
> 
> An alternative is to make your page implement the
> org.apache.tapestry.event.PageValidateListener and add a pageValidate
> method that does exactly what your first pageBeginRender method does.
> 
> >
> > Finally, what's the difference between pageBeginRender and
> > beginPageRender? Its a bit confusing :o(
> 
> beginPageRender is defined in org.apache.tapestry.AbstractPage and
> basically invokes all pageBeginRender methods of
> PageBeginRenderListener listeners registered for that page. In other
> words, don't override beginPageRender, but instead implement
> PageBeginRenderListener and use pageBeginRender.
> 
> R.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> 
> 


-- 
A bus station is where a bus stops. A train station is where a train
stops. On my desk I have a work station...

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


Re: Forwarding to a page on pageBeginRender

Posted by Yves Sy <yv...@gmail.com>.
Really now.. thanks for the tip


On Thu, 10 Mar 2005 17:17:16 -0500, Henri Dupre <he...@gmail.com> wrote:
> I'm not sure if it is the right solution but there is a
> PageRedirectException that can redirect you to another page.
> 
> Henri
> 
> 
> On Thu, 10 Mar 2005 09:56:31 +0000, Richard Kirby <rb...@capdm.com> wrote:
> >
> > On 10 Mar 2005, at 02:48, Yves Sy wrote:
> >
> > > Hello,
> > >
> > > I'm using pageBeginRender to check for a condition, which if true,
> > > should forward the user to another page:
> > >
> > > public void pageBeginRender(PageEvent e) {
> > >         MyVisit visit = (MyVisit) getEngine().getVisit();
> > >         if (visit != null && visit.isAuthenticated()) {
> > >             throw new PageRedirectException("search");
> > >         }
> > > }
> > >
> > > The above code works fine now but I still have some questions. One is,
> > > why doesn't the following code work instead:
> > >
> > > public void pageBeginRender(PageEvent e) {
> > >         MyVisit visit = (MyVisit) getEngine().getVisit();
> > >         if (visit != null && visit.isAuthenticated()) {
> > >             IRequestCycle cycle = e.getRequestCycle();
> > >             cycle.activate("search");
> > >         }
> > > }
> >
> > This doesn't work, because by the time pageBeginRender is called, the
> > RequestCycle has already been used to determine the activated page, so
> > cycle.activate no longer has an effect. That is why the
> > PageRedirectException is needed, as it causes the page rendering to be
> > aborted and restarted. Note that the PageRedirectException is actually
> > handled internally by Tapestry, and is not a client browser redirect.
> >
> > >
> > > I'm asking this because in ordinary servlets, you can either redirect
> > > or forward to another page whereas here, it seems we can only
> > > redirect.
> > >
> > > ...OR am I using the correct method to do this (pageBeginRender)?
> > > Maybe there's another place where things like these are supposed to be
> > > done...?
> >
> > An alternative is to make your page implement the
> > org.apache.tapestry.event.PageValidateListener and add a pageValidate
> > method that does exactly what your first pageBeginRender method does.
> >
> > >
> > > Finally, what's the difference between pageBeginRender and
> > > beginPageRender? Its a bit confusing :o(
> >
> > beginPageRender is defined in org.apache.tapestry.AbstractPage and
> > basically invokes all pageBeginRender methods of
> > PageBeginRenderListener listeners registered for that page. In other
> > words, don't override beginPageRender, but instead implement
> > PageBeginRenderListener and use pageBeginRender.
> >
> > R.
> >
> > ---------------------------------------------------------------------
> > 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
> 
> 


-- 
A bus station is where a bus stops. A train station is where a train
stops. On my desk I have a work station...

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


Re: Forwarding to a page on pageBeginRender

Posted by Henri Dupre <he...@gmail.com>.
I'm not sure if it is the right solution but there is a
PageRedirectException that can redirect you to another page.

Henri


On Thu, 10 Mar 2005 09:56:31 +0000, Richard Kirby <rb...@capdm.com> wrote:
> 
> On 10 Mar 2005, at 02:48, Yves Sy wrote:
> 
> > Hello,
> >
> > I'm using pageBeginRender to check for a condition, which if true,
> > should forward the user to another page:
> >
> > public void pageBeginRender(PageEvent e) {
> >         MyVisit visit = (MyVisit) getEngine().getVisit();
> >         if (visit != null && visit.isAuthenticated()) {
> >             throw new PageRedirectException("search");
> >         }
> > }
> >
> > The above code works fine now but I still have some questions. One is,
> > why doesn't the following code work instead:
> >
> > public void pageBeginRender(PageEvent e) {
> >         MyVisit visit = (MyVisit) getEngine().getVisit();
> >         if (visit != null && visit.isAuthenticated()) {
> >             IRequestCycle cycle = e.getRequestCycle();
> >             cycle.activate("search");
> >         }
> > }
> 
> This doesn't work, because by the time pageBeginRender is called, the
> RequestCycle has already been used to determine the activated page, so
> cycle.activate no longer has an effect. That is why the
> PageRedirectException is needed, as it causes the page rendering to be
> aborted and restarted. Note that the PageRedirectException is actually
> handled internally by Tapestry, and is not a client browser redirect.
> 
> >
> > I'm asking this because in ordinary servlets, you can either redirect
> > or forward to another page whereas here, it seems we can only
> > redirect.
> >
> > ...OR am I using the correct method to do this (pageBeginRender)?
> > Maybe there's another place where things like these are supposed to be
> > done...?
> 
> An alternative is to make your page implement the
> org.apache.tapestry.event.PageValidateListener and add a pageValidate
> method that does exactly what your first pageBeginRender method does.
> 
> >
> > Finally, what's the difference between pageBeginRender and
> > beginPageRender? Its a bit confusing :o(
> 
> beginPageRender is defined in org.apache.tapestry.AbstractPage and
> basically invokes all pageBeginRender methods of
> PageBeginRenderListener listeners registered for that page. In other
> words, don't override beginPageRender, but instead implement
> PageBeginRenderListener and use pageBeginRender.
> 
> R.
> 
> ---------------------------------------------------------------------
> 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: Forwarding to a page on pageBeginRender

Posted by Richard Kirby <rb...@capdm.com>.
On 10 Mar 2005, at 02:48, Yves Sy wrote:

> Hello,
>
> I'm using pageBeginRender to check for a condition, which if true,
> should forward the user to another page:
>
> public void pageBeginRender(PageEvent e) {
>         MyVisit visit = (MyVisit) getEngine().getVisit();
>         if (visit != null && visit.isAuthenticated()) {
>             throw new PageRedirectException("search");
>         }
> }
>
> The above code works fine now but I still have some questions. One is,
> why doesn't the following code work instead:
>
> public void pageBeginRender(PageEvent e) {
>         MyVisit visit = (MyVisit) getEngine().getVisit();
>         if (visit != null && visit.isAuthenticated()) {
>             IRequestCycle cycle = e.getRequestCycle();
>             cycle.activate("search");
>         }
> }

This doesn't work, because by the time pageBeginRender is called, the 
RequestCycle has already been used to determine the activated page, so 
cycle.activate no longer has an effect. That is why the 
PageRedirectException is needed, as it causes the page rendering to be 
aborted and restarted. Note that the PageRedirectException is actually 
handled internally by Tapestry, and is not a client browser redirect.

>
> I'm asking this because in ordinary servlets, you can either redirect
> or forward to another page whereas here, it seems we can only
> redirect.
>
> ...OR am I using the correct method to do this (pageBeginRender)?
> Maybe there's another place where things like these are supposed to be
> done...?

An alternative is to make your page implement the 
org.apache.tapestry.event.PageValidateListener and add a pageValidate 
method that does exactly what your first pageBeginRender method does.

>
> Finally, what's the difference between pageBeginRender and
> beginPageRender? Its a bit confusing :o(

beginPageRender is defined in org.apache.tapestry.AbstractPage and 
basically invokes all pageBeginRender methods of 
PageBeginRenderListener listeners registered for that page. In other 
words, don't override beginPageRender, but instead implement 
PageBeginRenderListener and use pageBeginRender.

R.


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