You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Rakesh A <ia...@rediffmail.com> on 2016/02/11 07:58:43 UTC

Correct way to get current page instance

Hi,
I see two possibilities to access current page instance using
"PageRequestHandlerTracker"
One

    IRequestHandler requestHandler =
RequestCycle.get().getActiveRequestHandler();
    if (requestHandler instanceof IRequestHandlerDelegate)
    {
      requestHandler = ((IRequestHandlerDelegate)
requestHandler).getDelegateHandler();
    }

    if (requestHandler instanceof IPageRequestHandler)
    {
      IPageRequestHandler pageRequestHandler = (IPageRequestHandler)
requestHandler;
      if (pageRequestHandler.isPageInstanceCreated())
      {
        IRequestablePage page = pageRequestHandler.getPage();
      }
    }

Two
   PageRequestHandlerTracker.getLastHandler(RequestCycle.get()).getPage();

Option#2 looks simpler, but
Is there any difference between the two?
What is correct way to get current page instance?

Regards,
Rakesh.A

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Correct-way-to-get-current-page-instance-tp4673548.html
Sent from the Users forum 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: Correct way to get current page instance

Posted by Rakesh A <ia...@rediffmail.com>.
Clear 

Thank you,
Rakesh.A

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Correct-way-to-get-current-page-instance-tp4673548p4673550.html
Sent from the Users forum 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: Correct way to get current page instance

Posted by Martin Grigorov <mg...@apache.org>.
Hi,

Both are correct but the second way is the simpler one.
PageRequestHandlerTracker's purpose is to give you the instance for the
requested page (#getFirstHandler()) and the last/response page.
E.g. if you are at PageA and you click a link that does
setResponsePage(PageB) then first=PageA and last=PageB.

Martin Grigorov
Wicket Training and Consulting
https://twitter.com/mtgrigorov

On Thu, Feb 11, 2016 at 7:58 AM, Rakesh A <ia...@rediffmail.com>
wrote:

> Hi,
> I see two possibilities to access current page instance using
> "PageRequestHandlerTracker"
> One
>
>     IRequestHandler requestHandler =
> RequestCycle.get().getActiveRequestHandler();
>     if (requestHandler instanceof IRequestHandlerDelegate)
>     {
>       requestHandler = ((IRequestHandlerDelegate)
> requestHandler).getDelegateHandler();
>     }
>
>     if (requestHandler instanceof IPageRequestHandler)
>     {
>       IPageRequestHandler pageRequestHandler = (IPageRequestHandler)
> requestHandler;
>       if (pageRequestHandler.isPageInstanceCreated())
>       {
>         IRequestablePage page = pageRequestHandler.getPage();
>       }
>     }
>
> Two
>    PageRequestHandlerTracker.getLastHandler(RequestCycle.get()).getPage();
>
> Option#2 looks simpler, but
> Is there any difference between the two?
> What is correct way to get current page instance?
>
> Regards,
> Rakesh.A
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/Correct-way-to-get-current-page-instance-tp4673548.html
> Sent from the Users forum 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
>
>