You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by dukehoops <ni...@doppelganger.com> on 2007/10/16 22:25:25 UTC

redirect request for Page A to page B without contructing A?

Hi,

I'd like to redirect requests for page A to page B without constructing page
A. Typically I'd use URL parsing in a servlet filter to accomplish this but
would like to figure out an OO way to do so.

In my RequestCycle I tried:

    @Override
    protected void onBeginRequest() {
      if(PageA.class.equals(this.getResponsePageClass()) && someCondition)
{
this.setResponsePage(pageB);
}
        super.onBeginRequest();
    }

The problem is that this.getResponsePageClass() is null in onBeginRequest.

Is overriding a RequestCycle method the right way to address this problem?
If so which method should I override given that:
-I need to ascertain that intended request target is PageA
-I'd like to avoid constructing page A

thanks
-nikita
-- 
View this message in context: http://www.nabble.com/redirect-request-for-Page-A-to-page-B-without-contructing-A--tf4636621.html#a13241857
Sent from the Wicket - User mailing list archive at Nabble.com.


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


Re: redirect request for Page A to page B without contructing A?

Posted by dukehoops <ni...@doppelganger.com>.
Implemented a SimplePageAuthorizationStrategy; works but there is a gotcha:

Say the home page has a (non-ajax) login form:
1. unauthenticated users navigates to home page and is authorized
2. user submits valid login info.
3. At this point I'd assumed Home page would be re-requested (does wicket do
Redirect-after-form-submit?)
4. However, Home page is redisplayed and isAuthorized method is never
executed after form submit.

Workaround seems to be doing setResponsePage in onSubmit method. This,
however, seems to complicate creating a reusable LoginPanel which would
return user to same page.

-nikita


public class HomePageAuthorizationStrategy extends
SimplePageAuthorizationStrategy{
    
    public HomePageAuthorizationStrategy(){
        super(HomePage.class, ProfilePage.class);        
    }
    
    /**
     * if user's signed-in redirect request for Home Page to user's
dashboard/profile
     */
    protected boolean isAuthorized() {
        this.getLogger().info("checking auth for home page access...");
        return ! ((MySession)Session.get()).isLoggedIn();
    }
    
    public Logger getLogger() {
        return Logger.getLogger(this.getClass().getName());
    }    
}


Eelco Hillenius wrote:
> 
>> If an already logged-in user types in our home URL we'd like the site to
>> redirect him/her to own profile page. If user's not logged in, they do
>> land
>> on home page. This is not to compel someone to sign in.
>>
>> So, for example below, PageA = site home page; PageB = user's own profile
>> page
> 
> Sounds like a custom authorization strategy would work great here.
> 
> Eelco
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/redirect-request-for-Page-A-to-page-B-without-contructing-A--tf4636621.html#a13262795
Sent from the Wicket - User mailing list archive at Nabble.com.


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


Re: redirect request for Page A to page B without contructing A?

Posted by Eelco Hillenius <ee...@gmail.com>.
> If an already logged-in user types in our home URL we'd like the site to
> redirect him/her to own profile page. If user's not logged in, they do land
> on home page. This is not to compel someone to sign in.
>
> So, for example below, PageA = site home page; PageB = user's own profile
> page

Sounds like a custom authorization strategy would work great here.

Eelco

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


Re: redirect request for Page A to page B without contructing A?

Posted by dukehoops <ni...@doppelganger.com>.
The use case is this:

If an already logged-in user types in our home URL we'd like the site to
redirect him/her to own profile page. If user's not logged in, they do land
on home page. This is not to compel someone to sign in.

So, for example below, PageA = site home page; PageB = user's own profile
page

-nikita



Eelco Hillenius wrote:
> 
> If it is intercepting what you're after (like you'd do when enforcing
> authorization), look at IComponentInstantiationListener. What is your
> use case?
> 
> Eelco
> 
> 
> On 10/16/07, dukehoops <ni...@doppelganger.com> wrote:
>>
>> Hi,
>>
>> I'd like to redirect requests for page A to page B without constructing
>> page
>> A. Typically I'd use URL parsing in a servlet filter to accomplish this
>> but
>> would like to figure out an OO way to do so.
>>
>> In my RequestCycle I tried:
>>
>>     @Override
>>     protected void onBeginRequest() {
>>       if(PageA.class.equals(this.getResponsePageClass()) &&
>> someCondition)
>> {
>> this.setResponsePage(pageB);
>> }
>>         super.onBeginRequest();
>>     }
>>
>> The problem is that this.getResponsePageClass() is null in
>> onBeginRequest.
>>
>> Is overriding a RequestCycle method the right way to address this
>> problem?
>> If so which method should I override given that:
>> -I need to ascertain that intended request target is PageA
>> -I'd like to avoid constructing page A
>>
>> thanks
>> -nikita
>> --
>> View this message in context:
>> http://www.nabble.com/redirect-request-for-Page-A-to-page-B-without-contructing-A--tf4636621.html#a13241857
>> Sent from the Wicket - User mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/redirect-request-for-Page-A-to-page-B-without-contructing-A--tf4636621.html#a13244889
Sent from the Wicket - User mailing list archive at Nabble.com.


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


Re: redirect request for Page A to page B without contructing A?

Posted by Eelco Hillenius <ee...@gmail.com>.
If it is intercepting what you're after (like you'd do when enforcing
authorization), look at IComponentInstantiationListener. What is your
use case?

Eelco


On 10/16/07, dukehoops <ni...@doppelganger.com> wrote:
>
> Hi,
>
> I'd like to redirect requests for page A to page B without constructing page
> A. Typically I'd use URL parsing in a servlet filter to accomplish this but
> would like to figure out an OO way to do so.
>
> In my RequestCycle I tried:
>
>     @Override
>     protected void onBeginRequest() {
>       if(PageA.class.equals(this.getResponsePageClass()) && someCondition)
> {
> this.setResponsePage(pageB);
> }
>         super.onBeginRequest();
>     }
>
> The problem is that this.getResponsePageClass() is null in onBeginRequest.
>
> Is overriding a RequestCycle method the right way to address this problem?
> If so which method should I override given that:
> -I need to ascertain that intended request target is PageA
> -I'd like to avoid constructing page A
>
> thanks
> -nikita
> --
> View this message in context: http://www.nabble.com/redirect-request-for-Page-A-to-page-B-without-contructing-A--tf4636621.html#a13241857
> Sent from the Wicket - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

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


Re: redirect request for Page A to page B without contructing A?

Posted by Nino Saturnino Martinez Vazquez Wael <ni...@jayway.dk>.
Why do you want to do this?

dukehoops wrote:
> Hi,
>
> I'd like to redirect requests for page A to page B without constructing page
> A. Typically I'd use URL parsing in a servlet filter to accomplish this but
> would like to figure out an OO way to do so.
>
> In my RequestCycle I tried:
>
>     @Override
>     protected void onBeginRequest() {
>       if(PageA.class.equals(this.getResponsePageClass()) && someCondition)
> {
> this.setResponsePage(pageB);
> }
>         super.onBeginRequest();
>     }
>
> The problem is that this.getResponsePageClass() is null in onBeginRequest.
>
> Is overriding a RequestCycle method the right way to address this problem?
> If so which method should I override given that:
> -I need to ascertain that intended request target is PageA
> -I'd like to avoid constructing page A
>
> thanks
> -nikita
>   

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


Re: redirect request for Page A to page B without contructing A?

Posted by Eelco Hillenius <ee...@gmail.com>.
> What I have done is to check in MyApplication.getHomePage():
>
>
>         public Class getHomePage() {
>
>                 IUser user = getMySession().getCurrentUser();
>
>                 return user == null ? Index.class : UserHome.class;
>         }

That's another fine solution if the home page is only what you're after.

Eelco

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


Re: redirect request for Page A to page B without contructing A?

Posted by Doug Leeper <do...@yahoo.com>.
What I have done is to check in MyApplication.getHomePage():


	public Class getHomePage() {

		IUser user = getMySession().getCurrentUser();

		return user == null ? Index.class : UserHome.class;
	}


-- 
View this message in context: http://www.nabble.com/redirect-request-for-Page-A-to-page-B-without-contructing-A--tf4636621.html#a13246212
Sent from the Wicket - User mailing list archive at Nabble.com.


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