You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Paolo Di Tommaso <pa...@gmail.com> on 2007/08/03 11:53:49 UTC

How discover the caller page (wicket 1.2.x)

Dear Wicket gurus,

Suppose I have two Wicket page, let's say page A and B,
with the following simple navigation rule A --> B using something like

A. setResponsePage( new B() )

At compiles time A know B , but B does not know A.
It there a way to get - at runtime - from page B the reference to caller A
page instance?

Basically I'm trying to implement something like the HTTP referer mechanism.


Any ideas ?



Thanks, Paolo

Re: How discover the caller page (wicket 1.2.x)

Posted by Al Maw <wi...@almaw.com>.
Fabio Fioretti wrote:
> On 8/3/07, Al Maw <wi...@almaw.com> wrote:
>> If you're going to be using the previous page in your new page (for
>> example, to provide a link back to it) then you need a reference to it.
>> You may as well pass this in the constructor.
> 
> But is it the only way to do this really?
> 
> An automatic mechanism to get the caller page without passing it in
> the constructor would be cool. Does it exist?

Why would it be cool? The method required at the moment is far more 
explicit and obvious. In particular, it's just plain Java and not some 
magic.

If have some automatic mechanism it would need to cope with:

  - What happens when you do redirects? Particularly, what if you throw
    RestartResponseException() in a page's constructor?

  - What if you came via a stateless page?

  - What happens when you access pages from two page maps simultaneously?

  - How do you make sure that the previous page that you're going to use
    in your new page instance doesn't disappear out of the page map
    stack because no one has used it recently and no one has a reference
    to it any more?

That said, if you really want to you could implement this yourself in 
any one of a number of ways.

For example, you could keep the last rendered Page instance in a custom 
Session and have a base page class of yours call 
yourSession.setLastRendered(this) in its onDetach() method. There may be 
race conditions if people are browsing pages in two tabs at once in 
different page maps, but you'll probably never notice them. Or you could 
do something similar but with a ThreadLocal you can set in a custom 
RequestCycle.

All of this is really complex and unobvious compared to just passing the 
page in in the constructor, which is reliable, easy and simple. So, err, 
why don't you just do that?

Regards,

Al

-- 
Alastair Maw
Wicket-biased blog at http://herebebeasties.com

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


Re: How discover the caller page (wicket 1.2.x)

Posted by Fabio Fioretti <wi...@gmail.com>.
On 8/3/07, Al Maw <wi...@almaw.com> wrote:
> If you're going to be using the previous page in your new page (for
> example, to provide a link back to it) then you need a reference to it.
> You may as well pass this in the constructor.

But is it the only way to do this really?

An automatic mechanism to get the caller page without passing it in
the constructor would be cool. Does it exist?


Best regards,

Fabio Fioretti - WindoM

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


Re: How discover the caller page (wicket 1.2.x)

Posted by Al Maw <wi...@almaw.com>.
Why do you want to avoid this?

If you're going to be using the previous page in your new page (for 
example, to provide a link back to it) then you need a reference to it. 
You may as well pass this in the constructor.

Alastair

Paolo Di Tommaso wrote:
> Yes, but I would to avoid this, basically I'm looking for a way to discover
> dinamically the calling wicket page instance (if exists ..)
> 
> 
> Thanks, Paolo
> 
> 
> On 8/3/07, Gerolf Seitz <ge...@gmail.com> wrote:
>> you could have a constructor B(Page referrer)
>> and pass the referrer page as a parameter like:
>> this.setResponsePage(new B(this));
>>
>> hth,
>>   gerolf
>>
>> On 8/3/07, Paolo Di Tommaso <pa...@gmail.com> wrote:
>>> Dear Wicket gurus,
>>>
>>> Suppose I have two Wicket page, let's say page A and B,
>>> with the following simple navigation rule A --> B using something like
>>>
>>> A. setResponsePage( new B() )
>>>
>>> At compiles time A know B , but B does not know A.
>>> It there a way to get - at runtime - from page B the reference to caller
>> A
>>> page instance?
>>>
>>> Basically I'm trying to implement something like the HTTP referer
>>> mechanism.

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


Re: How discover the caller page (wicket 1.2.x)

Posted by Paolo Di Tommaso <pa...@gmail.com>.
Yes, but I would to avoid this, basically I'm looking for a way to discover
dinamically the calling wicket page instance (if exists ..)


Thanks, Paolo


On 8/3/07, Gerolf Seitz <ge...@gmail.com> wrote:
>
> you could have a constructor B(Page referrer)
> and pass the referrer page as a parameter like:
> this.setResponsePage(new B(this));
>
> hth,
>   gerolf
>
> On 8/3/07, Paolo Di Tommaso <pa...@gmail.com> wrote:
> >
> > Dear Wicket gurus,
> >
> > Suppose I have two Wicket page, let's say page A and B,
> > with the following simple navigation rule A --> B using something like
> >
> > A. setResponsePage( new B() )
> >
> > At compiles time A know B , but B does not know A.
> > It there a way to get - at runtime - from page B the reference to caller
> A
> > page instance?
> >
> > Basically I'm trying to implement something like the HTTP referer
> > mechanism.
> >
> >
> > Any ideas ?
> >
> >
> >
> > Thanks, Paolo
> >
>

Re: How discover the caller page (wicket 1.2.x)

Posted by Gerolf Seitz <ge...@gmail.com>.
you could have a constructor B(Page referrer)
and pass the referrer page as a parameter like:
this.setResponsePage(new B(this));

hth,
  gerolf

On 8/3/07, Paolo Di Tommaso <pa...@gmail.com> wrote:
>
> Dear Wicket gurus,
>
> Suppose I have two Wicket page, let's say page A and B,
> with the following simple navigation rule A --> B using something like
>
> A. setResponsePage( new B() )
>
> At compiles time A know B , but B does not know A.
> It there a way to get - at runtime - from page B the reference to caller A
> page instance?
>
> Basically I'm trying to implement something like the HTTP referer
> mechanism.
>
>
> Any ideas ?
>
>
>
> Thanks, Paolo
>