And thats the question I was looking for - how do I get the current page id
within the class that generates the url which is no component and the
second question was how do I get the page to that id, because (Page)
WebSession.get().getPageManager().getPage(i.get()) returns null for int i
0-10, event if I cleared the browsers cache / restarted the server.

kind regards and big thanks for all the help!

Tobias

2014-09-09 14:28 GMT+02:00 Martin Grigorov <mgrigo...@apache.org>:

> Session#pageId is a counter that is used to give an id to the next created
> page.
> It is not the id of the currently used page!
>
> You will need to provide the pageId somehow to the class that generates the
> url.
>
> Martin Grigorov
> Wicket Training and Consulting
> https://twitter.com/mtgrigorov
>
>
> On Tue, Sep 9, 2014 at 3:13 PM, Tobias Soloschenko <
> tobiassolosche...@googlemail.com> wrote:
>
> > The method getPage() is not available at the place where I'm building the
> > link - I'm not within a component and I try to get the page by content of
> > the session. :-)
> >
> > I didn't modified the Session - the pageId is stored in
> > org.apache.wicket.Session.pageId which is an AtomicInteger
> >
> >
> > 2014-09-09 14:06 GMT+02:00 Martin Grigorov <mgrigo...@apache.org>:
> >
> > > Pass the pageId as a query string parameter.
> > >
> > > PageParameters params = new PageParameters();
> > > params.set("pageId", getPage().getPageId());
> > > theUrlToTheReference = requestCycle.urlFor(yourResRef, params);
> > >
> > > Then in the IResource (better extend AbstractResource) just read it
> from
> > > the request parameters.
> > >
> > > Storing the pageId in the session is not OK because the user may open
> two
> > > different pages in separate tabs/windows and this will break.
> > >
> > >
> > > Martin Grigorov
> > > Wicket Training and Consulting
> > > https://twitter.com/mtgrigorov
> > >
> > >
> > > On Tue, Sep 9, 2014 at 3:01 PM, Tobias Soloschenko <
> > > tobiassolosche...@googlemail.com> wrote:
> > >
> > > > Thanks again for the fast answer. My code now looks this way:
> > > >
> > > >             Field declaredField =
> > > > WebSession.get().getClass().getSuperclass()
> > > >                 .getDeclaredField("pageId");
> > > >
> > > >             declaredField.setAccessible(true);
> > > >             AtomicInteger i = (AtomicInteger)
> > > > declaredField.get(WebSession.get());
> > > >             Page page = (Page) WebSession.get().getPageManager()
> > > >                 .getPage(i.get());
> > > >
> > > >             AjaxRequestTarget newAjaxRequestTarget =
> ((WebApplication)
> > > > Application.get())
> > > >                 .newAjaxRequestTarget(page);
> > > >
> > > >             RequestCycle.get().scheduleRequestHandlerAfterCurrent(
> > > >                 newAjaxRequestTarget);
> > > >
> > > > I dont know how to get the current pageId but from the Session. The
> > page
> > > at
> > > > this place is null. :-(
> > > >
> > > >
> > > >
> > > > 2014-09-09 13:53 GMT+02:00 Martin Grigorov <mgrigo...@apache.org>:
> > > >
> > > > > On Tue, Sep 9, 2014 at 2:05 PM, Tobias Soloschenko <
> > > > > tobiassolosche...@googlemail.com> wrote:
> > > > >
> > > > > > Hi again,
> > > > > >
> > > > > > I tried out that code you mentioned here.
> > > > > > WebSession.get().getPageManager().getPage(int i) returns
> > > > IManageablePage
> > > > > > which is not applicable as argument for newAjaxRequestTarget.
> > > > > >
> > > > >
> > > > > cast it
> > > > > it is known that in your environment you don't use any custom
> > > > > IManageablePage/IRequestablePage impls (see IPageFactory)
> > > > >
> > > > >
> > > > > >
> > > > > > The second thing is how do I get the instance of a page by class
> > with
> > > > the
> > > > > > last page id not from within a component (this would be simple
> > > > > getPage())?
> > > > > >
> > > > >
> > > > > I didn't get this
> > > > > Please re-phrase
> > > > >
> > > > >
> > > > > >
> > > > > > 2014-09-09 11:51 GMT+02:00 Martin Grigorov <mgrigo...@apache.org
> >:
> > > > > >
> > > > > > > I've re-read the message and I think I got it.
> > > > > > > What you really need is a mounted resource
> > > > > > > (WebApplication#mountResource(someResourceReference))
> > > > > > > To get a url to it use: theUrl =
> requestCycle.urlFor(sameResRef,
> > > > > > > parametersWithPageId)
> > > > > > > Wicket.Ajax.get({"u": theUrl, ...})
> > > > > > > In IResource#respond() you can create AjaxRequestTarget with:
> > > > > > >
> > > > > > > Page page =
> > session.getPageManager().get(parameters.get("pageId"))
> > > > > > > target = webApplication.newAjaxRequestTarget(page)
> > > > > > > requestCycle.scheduleRequestHandlerAfterCurrent(target);
> > > > > > > page.send(page, Broadcast.BREADTH, new SomeEvent(target))
> > > > > > >
> > > > > > > in SomeComponent#onEvent() use someEvent.getTarget().add(this)
> to
> > > add
> > > > > the
> > > > > > > component when SomeEvent is broadcasted
> > > > > > >
> > > > > > > Martin Grigorov
> > > > > > > Wicket Training and Consulting
> > > > > > > https://twitter.com/mtgrigorov
> > > > > > >
> > > > > > >
> > > > > > > On Tue, Sep 9, 2014 at 12:40 PM, Richter, Marvin <
> > > > > > > marvin.rich...@freenetdigital.com> wrote:
> > > > > > >
> > > > > > > > What you are looking for is the Wicket Event mechanism.
> > > > > > > >
> > > > > > > > This allows you to send a broadcast to a specified Component
> > > (e.g.
> > > > > the
> > > > > > > > current page) and a payload (e.g. your custom event type
> which
> > > > > contains
> > > > > > > > information).
> > > > > > > >
> > > > > > > > In the Components which should react on the event you
> override
> > > the
> > > > > > method
> > > > > > > > onEvent, check if the event is of your type and if so, do
> with
> > > the
> > > > > > event
> > > > > > > > payload whatever you want.
> > > > > > > >
> > > > > > > > Check out
> > > > > > > >
> > > > > > >
> > > > > >
> > > > >
> > > >
> > >
> >
> http://www.wicket-library.com/wicket-examples/events/wicket/bookmarkable/org.apache.wicket.examples.source.SourcesPage?1&SourcesPage_class=org.apache.wicket.examples.events.DecoupledAjaxUpdatePage
> > > > > > > > for a good example.
> > > > > > > >
> > > > > > > > Best,
> > > > > > > > Marvin
> > > > > > > >
> > > > > > > > -----Original Message-----
> > > > > > > > From: Tobias Soloschenko [mailto:
> > > tobiassolosche...@googlemail.com]
> > > > > > > > Sent: Tuesday, September 09, 2014 11:31 AM
> > > > > > > > To: users@wicket.apache.org
> > > > > > > > Subject: Re: Global Ajax Event Handler
> > > > > > > >
> > > > > > > > Hi,
> > > > > > > >
> > > > > > > > thanks for the answer, but this is only a client side event
> > hook
> > > > not
> > > > > > for
> > > > > > > > processing a request to the Server. I added a pseudo code to
> > the
> > > > > > question
> > > > > > > > of martin who asked me what I exactly want to do.
> > > > > > > >
> > > > > > > > Thanks anyway for the fast answer!
> > > > > > > >
> > > > > > > > kind regards,
> > > > > > > >
> > > > > > > > Tobias
> > > > > > > >
> > > > > > > > > Am 09.09.2014 um 11:06 schrieb Tom Götz <t...@decoded.de>:
> > > > > > > > >
> > > > > > > > > See
> > > > https://cwiki.apache.org/confluence/display/WICKET/Wicket+Ajax
> > > > > ,
> > > > > > > > section "Global Ajax call listeners“.
> > > > > > > > >
> > > > > > > > > Cheers,
> > > > > > > > >   -Tom
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >> On 09.09.2014, at 10:58, Tobias Soloschenko <
> > > > > > > > tobiassolosche...@googlemail.com> wrote:
> > > > > > > > >>
> > > > > > > > >> Hi all,
> > > > > > > > >>
> > > > > > > > >> is there a way to register a global ajax event handler
> > within
> > > > > > Wicket?
> > > > > > > > For normal there is the AbstractDefaultAjaxBehavior which is
> > > added
> > > > > to a
> > > > > > > > component. And then the CallbackScript can be obtained and
> used
> > > > > within
> > > > > > a
> > > > > > > > OnDomReadyHeaderItem for example.
> > > > > > > > >>
> > > > > > > > >> Is there a way to do this on application level so that Im
> > able
> > > > to
> > > > > > get
> > > > > > > > the CallbackScript from the instantiated Application?
> > > > > > > > >>
> > > > > > > > >> kind regards
> > > > > > > > >>
> > > > > > > > >> Tobias
> > > > > > > > >>
> > > > > >
> > ---------------------------------------------------------------------
> > > > > > > > >> To unsubscribe, e-mail:
> users-unsubscr...@wicket.apache.org
> > > > > > > > >> For additional commands, e-mail:
> > users-h...@wicket.apache.org
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > ---------------------------------------------------------------------
> > > > > > > > To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
> > > > > > > > For additional commands, e-mail:
> users-h...@wicket.apache.org
> > > > > > > >
> > > > > > > >
> > > > > > >
> > > > > >
> > > > >
> > > >
> > >
> >
>

Reply via email to