You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Hugo Palma <hu...@gmail.com> on 2010/11/08 12:43:11 UTC

Redirecting to page on load

I would like for a given page to force a redirect to a different page before
it's rendered if a given condition is met.
I could use a simple Response.sendRedirect but that would mean i would have
to provide the page name in string format. I would like to avoid having to
do this because it would make code refactoring harder and more error prone.

So, any way i can redirect using page classes only ?
Thanks.

Re: Redirecting to page on load

Posted by Everton Agner <to...@gmail.com>.
A tip... I don't know if the code for your checking is heavyweight, but
sometimes it's recommended to check in the onActivate() if the request is a
XRH or not... because component events triggers it too. You can do so by
@Inject'ing Request (org.apache.tapestry5.services) and calling isXHR()
method.

Of course, that is only necessary if the code is heavy and your XHR checking
for redirection isn't needed...

_______________________
Everton Agner Ramos


2010/11/8 Juan E. Maya <ma...@gmail.com>

> Yes :) I am aware of it :) I thought he wanted to do it outside a page
> :) Thanks! :)
>
> On Mon, Nov 8, 2010 at 1:32 PM, Thiago H. de Paula Figueiredo
> <th...@gmail.com> wrote:
> > On Mon, 08 Nov 2010 09:57:47 -0200, Juan E. Maya <ma...@gmail.com>
> > wrote:
> >
> >> Hi Hugo,
> >
> > Hi, Juan!
> >
> >> what u could do is to create the Link to the page u want to send
> >> redirect and then use the response. It would be something like:
> >> Link redirectTo =
> >> pageRenderLinkSource.createPageRenderLinkWithContext(pageClass,
> >> context);
> >> response.sendRedirect(link);
> >
> > The onActivate() return value is the way to go in Tapestry. Using
> > Response.sendRedirect() should only be used in RequestFilters and
> > Dispatchers.
> >
> > --
> > Thiago H. de Paula Figueiredo
> > Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,
> and
> > instructor
> > Owner, Ars Machina Tecnologia da Informação Ltda.
> > http://www.arsmachina.com.br
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: Redirecting to page on load

Posted by "Juan E. Maya" <ma...@gmail.com>.
Yes :) I am aware of it :) I thought he wanted to do it outside a page
:) Thanks! :)

On Mon, Nov 8, 2010 at 1:32 PM, Thiago H. de Paula Figueiredo
<th...@gmail.com> wrote:
> On Mon, 08 Nov 2010 09:57:47 -0200, Juan E. Maya <ma...@gmail.com>
> wrote:
>
>> Hi Hugo,
>
> Hi, Juan!
>
>> what u could do is to create the Link to the page u want to send
>> redirect and then use the response. It would be something like:
>> Link redirectTo =
>> pageRenderLinkSource.createPageRenderLinkWithContext(pageClass,
>> context);
>> response.sendRedirect(link);
>
> The onActivate() return value is the way to go in Tapestry. Using
> Response.sendRedirect() should only be used in RequestFilters and
> Dispatchers.
>
> --
> Thiago H. de Paula Figueiredo
> Independent Java, Apache Tapestry 5 and Hibernate consultant, developer, and
> instructor
> Owner, Ars Machina Tecnologia da Informação Ltda.
> http://www.arsmachina.com.br
>

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


Re: Redirecting to page on load

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Mon, 08 Nov 2010 09:57:47 -0200, Juan E. Maya <ma...@gmail.com>  
wrote:

> Hi Hugo,

Hi, Juan!

> what u could do is to create the Link to the page u want to send
> redirect and then use the response. It would be something like:
> Link redirectTo =
> pageRenderLinkSource.createPageRenderLinkWithContext(pageClass,
> context);
> response.sendRedirect(link);

The onActivate() return value is the way to go in Tapestry. Using  
Response.sendRedirect() should only be used in RequestFilters and  
Dispatchers.

-- 
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,  
and instructor
Owner, Ars Machina Tecnologia da Informação Ltda.
http://www.arsmachina.com.br

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


Re: Redirecting to page on load

Posted by "Juan E. Maya" <ma...@gmail.com>.
Hi Hugo,

what u could do is to create the Link to the page u want to send
redirect and then use the response. It would be something like:
Link redirectTo =
pageRenderLinkSource.createPageRenderLinkWithContext(pageClass,
context);
response.sendRedirect(link);

I hope it helps! :)

On Mon, Nov 8, 2010 at 12:43 PM, Hugo Palma <hu...@gmail.com> wrote:
> I would like for a given page to force a redirect to a different page before
> it's rendered if a given condition is met.
> I could use a simple Response.sendRedirect but that would mean i would have
> to provide the page name in string format. I would like to avoid having to
> do this because it would make code refactoring harder and more error prone.
>
> So, any way i can redirect using page classes only ?
> Thanks.
>

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


Re: Redirecting to page on load

Posted by Hugo Palma <hu...@gmail.com>.
That did the trick.
Thanks.

On Mon, Nov 8, 2010 at 11:52, Richard Hill <ri...@su3analytics.com> wrote:

>
> I believe you can do this by having onActivate() return a Page, or just
> the string name of your page:
>
> public String onActivate() {
>
>  ... test for condition
>
>  if (condition) {
>     return "MyPageName";
>  } else {
>      return null;  // keeps you on this page
>  }
>
> }
>
> onActivate() is called before any rendering.
>
>
>
> -----Original Message-----
> From: Hugo Palma <hu...@gmail.com>
> Reply-to: "Tapestry users" <us...@tapestry.apache.org>
> To: Tapestry users <us...@tapestry.apache.org>
> Subject: Redirecting to page on load
> Date: Mon, 8 Nov 2010 11:43:11 +0000
>
> I would like for a given page to force a redirect to a different page
> before
> it's rendered if a given condition is met.
> I could use a simple Response.sendRedirect but that would mean i would have
> to provide the page name in string format. I would like to avoid having to
> do this because it would make code refactoring harder and more error prone.
>
> So, any way i can redirect using page classes only ?
> Thanks.
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


-- 

LinkedIn <http://www.linkedin.com/in/hugopalma>
Twitter<http://twitter.com/hugompalma>

Re: Redirecting to page on load

Posted by Richard Hill <ri...@su3analytics.com>.
I believe you can do this by having onActivate() return a Page, or just
the string name of your page:

public String onActivate() {

  ... test for condition

  if (condition) {
     return "MyPageName";
  } else {
      return null;  // keeps you on this page
  }
  
}

onActivate() is called before any rendering.



-----Original Message-----
From: Hugo Palma <hu...@gmail.com>
Reply-to: "Tapestry users" <us...@tapestry.apache.org>
To: Tapestry users <us...@tapestry.apache.org>
Subject: Redirecting to page on load
Date: Mon, 8 Nov 2010 11:43:11 +0000

I would like for a given page to force a redirect to a different page before
it's rendered if a given condition is met.
I could use a simple Response.sendRedirect but that would mean i would have
to provide the page name in string format. I would like to avoid having to
do this because it would make code refactoring harder and more error prone.

So, any way i can redirect using page classes only ?
Thanks.



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