Page redirect in tapestry5

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Page redirect in tapestry5

Anbazhagan
Hi All,

I am working in web application using tapestry framework. I have
following pages a,b,c,d and Index in my application. In Index page,
check some condition and redirect to a particular page. My code,

|if(null!=cookieVal){if(cookieVal.equalsIgnoreCase("a")){returnA.class;}elseif(cookieVal.equalsIgnoreCase("b")){returnB.class;}elseif(cookieVal.equalsIgnoreCase("c")){returnC.class;}elseif(cookieVal.equalsIgnoreCase("d")){returnD.class;}}|

Here conditions are increased if pages are increased. How can I optimize
this condition check and redirect to particular page.

--
Best Regards,
Anbazhagan.G

Reply | Threaded
Open this post in threaded view
|

Re: Page redirect in tapestry5

Jens Breitenstein
You can just return the string and tapestry locates the page on its own

return cookieVal;

Just make sure the cookieval is a valid page name (class name without package)

Jens

Von meinem iPhone gesendet

> Am 04.03.2016 um 07:12 schrieb Anbazhagan.G <[hidden email]>:
>
> Hi All,
>
> I am working in web application using tapestry framework. I have following pages a,b,c,d and Index in my application. In Index page, check some condition and redirect to a particular page. My code,
>
> |if(null!=cookieVal){if(cookieVal.equalsIgnoreCase("a")){returnA.class;}elseif(cookieVal.equalsIgnoreCase("b")){returnB.class;}elseif(cookieVal.equalsIgnoreCase("c")){returnC.class;}elseif(cookieVal.equalsIgnoreCase("d")){returnD.class;}}|
>
> Here conditions are increased if pages are increased. How can I optimize this condition check and redirect to particular page.
>
> --
> Best Regards,
> Anbazhagan.G
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Page redirect in tapestry5

JumpStart
This example includes returning the logical page name as String:

        http://jumpstart.doublenegative.com.au/jumpstart7/examples/navigation/returntypes1 <http://jumpstart.doublenegative.com.au/jumpstart7/examples/navigation/returntypes1>

Geoff

> On 4 Mar 2016, at 2:22 pm, [hidden email] wrote:
>
> You can just return the string and tapestry locates the page on its own
>
> return cookieVal;
>
> Just make sure the cookieval is a valid page name (class name without package)
>
> Jens
>
> Von meinem iPhone gesendet
>
>> Am 04.03.2016 um 07:12 schrieb Anbazhagan.G <[hidden email]>:
>>
>> Hi All,
>>
>> I am working in web application using tapestry framework. I have following pages a,b,c,d and Index in my application. In Index page, check some condition and redirect to a particular page. My code,
>>
>> |if(null!=cookieVal){if(cookieVal.equalsIgnoreCase("a")){returnA.class;}elseif(cookieVal.equalsIgnoreCase("b")){returnB.class;}elseif(cookieVal.equalsIgnoreCase("c")){returnC.class;}elseif(cookieVal.equalsIgnoreCase("d")){returnD.class;}}|
>>
>> Here conditions are increased if pages are increased. How can I optimize this condition check and redirect to particular page.
>>
>> --
>> Best Regards,
>> Anbazhagan.G
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>

Reply | Threaded
Open this post in threaded view
|

Re: Page redirect in tapestry5

trsvax
Using data directly from the client is never a good idea. While in this
case it's probably fine it's a bad habit to fail into. I would make a enum
with the Cookie string and the page class. Use enum.valueOf(cookie) to
convert from String to enum and then return the class from the enum. I
suspect you can declare the enum in the index class so you can add to it
without restarting the web server. This will also allow you to refactor
your page classes.

On Friday, March 4, 2016, JumpStart <[hidden email]>
wrote:

> This example includes returning the logical page name as String:
>
>
> http://jumpstart.doublenegative.com.au/jumpstart7/examples/navigation/returntypes1
> <
> http://jumpstart.doublenegative.com.au/jumpstart7/examples/navigation/returntypes1
> >
>
> Geoff
>
> > On 4 Mar 2016, at 2:22 pm, [hidden email] <javascript:;> wrote:
> >
> > You can just return the string and tapestry locates the page on its own
> >
> > return cookieVal;
> >
> > Just make sure the cookieval is a valid page name (class name without
> package)
> >
> > Jens
> >
> > Von meinem iPhone gesendet
> >
> >> Am 04.03.2016 um 07:12 schrieb Anbazhagan.G <[hidden email]
> <javascript:;>>:
> >>
> >> Hi All,
> >>
> >> I am working in web application using tapestry framework. I have
> following pages a,b,c,d and Index in my application. In Index page, check
> some condition and redirect to a particular page. My code,
> >>
> >>
> |if(null!=cookieVal){if(cookieVal.equalsIgnoreCase("a")){returnA.class;}elseif(cookieVal.equalsIgnoreCase("b")){returnB.class;}elseif(cookieVal.equalsIgnoreCase("c")){returnC.class;}elseif(cookieVal.equalsIgnoreCase("d")){returnD.class;}}|
> >>
> >> Here conditions are increased if pages are increased. How can I
> optimize this condition check and redirect to particular page.
> >>
> >> --
> >> Best Regards,
> >> Anbazhagan.G
> >>
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [hidden email]
> <javascript:;>
> > For additional commands, e-mail: [hidden email]
> <javascript:;>
> >
>
>
Reply | Threaded
Open this post in threaded view
|

Re: Page redirect in tapestry5

Jens Breitenstein
Hi Barry,

Am 04/03/16 um 13:00 schrieb Barry Books:
> Using data directly from the client is never a good idea. While in this
> case it's probably fine it's a bad habit to fail into.
Agreed
> I would make a enum
> with the Cookie string and the page class. Use enum.valueOf(cookie) to
> convert from String to enum and then return the class from the enum. I
> suspect you can declare the enum in the index class so you can add to it
> without restarting the web server. This will also allow you to refactor
> your page classes.
This means changing the java code whenever a page is added/removed which
the author initially tried to avoid. But there is maybe another way:
What about using PageRenderLinkSource to force a call to the page,
particularly the onPassivate method like

try {
     final Link link =_prls.createPageRenderLink(page);     return page;
}catch (final Exception e) {
     // page is not existing, or not accessible for security reasons
     return Index.class;
}

--- snip ---

sample of "your page"

@RequiresAuthentication // todo add roles and more Object onPassivate()
{
        ...
}


In case the user is not authenticated or does not have roles an
exception is thrown, therefore the page detection is considerably
dynamic and not static compared to using if cascades or an enum. But I
guess there are still more ways to solve it...


Jens


>
> On Friday, March 4, 2016, JumpStart <[hidden email]>
> wrote:
>
>> This example includes returning the logical page name as String:
>>
>>
>> http://jumpstart.doublenegative.com.au/jumpstart7/examples/navigation/returntypes1
>> <
>> http://jumpstart.doublenegative.com.au/jumpstart7/examples/navigation/returntypes1
>> Geoff
>>
>>> On 4 Mar 2016, at 2:22 pm, [hidden email] <javascript:;> wrote:
>>>
>>> You can just return the string and tapestry locates the page on its own
>>>
>>> return cookieVal;
>>>
>>> Just make sure the cookieval is a valid page name (class name without
>> package)
>>> Jens
>>>
>>> Von meinem iPhone gesendet
>>>
>>>> Am 04.03.2016 um 07:12 schrieb Anbazhagan.G <[hidden email]
>> <javascript:;>>:
>>>> Hi All,
>>>>
>>>> I am working in web application using tapestry framework. I have
>> following pages a,b,c,d and Index in my application. In Index page, check
>> some condition and redirect to a particular page. My code,
>>>>
>> |if(null!=cookieVal){if(cookieVal.equalsIgnoreCase("a")){returnA.class;}elseif(cookieVal.equalsIgnoreCase("b")){returnB.class;}elseif(cookieVal.equalsIgnoreCase("c")){returnC.class;}elseif(cookieVal.equalsIgnoreCase("d")){returnD.class;}}|
>>>> Here conditions are increased if pages are increased. How can I
>> optimize this condition check and redirect to particular page.
>>>> --
>>>> Best Regards,
>>>> Anbazhagan.G
>>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: [hidden email]
>> <javascript:;>
>>> For additional commands, e-mail: [hidden email]
>> <javascript:;>
>>