Fabio Fioretti wrote:
On 8/3/07, Al Maw <[EMAIL PROTECTED]> 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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to