You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Daniel Stoch <da...@gmail.com> on 2014/12/09 12:24:07 UTC

How to call onResourceRequested for page behavior in ajax update (Atmosphere related)

Hi,

I have a behavior which implements IResourceListener
(AtmosphereBehavior). The problem is when this behavior is added to
page during ajax request (eg. some panel is dynamically added to page)
- then onResourceRequested is not invoked for page. So when using
AtmosphereBehavior the suspended connection from the client is not
registered.

How should I solve this problem: how and when call this
onResourceRequested method?

--
Best regards,
Daniel

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


Re: How to call onResourceRequested for page behavior in ajax update (Atmosphere related)

Posted by Martin Grigorov <mg...@apache.org>.
On Fri, Dec 12, 2014 at 4:32 PM, Daniel Stoch <da...@gmail.com>
wrote:

> On Fri, Dec 12, 2014 at 11:38 AM, Martin Grigorov <mg...@apache.org>
> wrote:
> > I see it is a bit ugly, but oh well... this is how it works now.
> >
> > in YourComponent#renderHead():
> >
> > AtmosphereBehavior atmo =
> > getPage().getBehaviors(AtmosphereBehavior.class).get(0);
> > CharSequence callbackUrl = atmo.getCallbackUrl();
> > headerResponse.render(OnDomReadyHeaderItem.forScript("Wicket.Ajax.get({u:
> > "+callbackUrl+"})"));
>
> Thanks, it works.
> But I call whole atmo.renderHead(page, response); method.
>

Right! This is the right way!


>
> >
> > You may need to use some flag to make sure this happens once per page
> > instance. Otherwise every re-render of such component will initialize a
> new
> > web socket connection (or whatever fallback you may use)
> >
>
> Hmmm, do we really need this check if I call whole atmo.renderHead method?
>

I think so.
Without the flag I think there will be more than one Atmosphere connections
to the server.


>
> Thanks for your help.
>
> --
> Daniel
>
>
> > Martin Grigorov
> > Wicket Training and Consulting
> > https://twitter.com/mtgrigorov
> >
> > On Fri, Dec 12, 2014 at 11:36 AM, Daniel Stoch <da...@gmail.com>
> > wrote:
> >
> >> Hi,
> >>
> >> Ok, I think I didn't described a problem well.
> >>
> >> When you add a component which subscribes some events, then
> >> AtmosphereBehavior is added to page. But the wicketAtmosphere JS
> >> callback is registered inside AtmosphereBehavior.renderHead() method,
> >> so only (I think) when the whole page is rendered. When you add a
> >> component using ajax, then this code (renderHead) is not called, so
> >> events are not broadcasted to client: because page is not registered
> >> in EventBus and does not have atmosphere resource assigned.
> >>
> >> So maybe my original question should be: how to invode this JS
> >> callback from AtmosphereBehavior.renderHead in ajax requests?
> >>
> >> --
> >> Daniel
> >>
> >> On Wed, Dec 10, 2014 at 12:19 PM, Daniel Stoch <da...@gmail.com>
> >> wrote:
> >> > Hi,
> >> >
> >> > It seems that I am using an older version of AtmosphereBehavior which
> >> > implements IResourceListener. Since 6.17.0 this implementation was
> >> > removed and the code is moved to onRequest() method.
> >> > So I must check a newer version, maybe my problem is solved.
> >> >
> >> > Thanks for a tip!
> >> >
> >> > --
> >> > Daniel
> >> >
> >> > On Wed, Dec 10, 2014 at 11:03 AM, Martin Grigorov <
> mgrigorov@apache.org>
> >> wrote:
> >> >> Hi,
> >> >>
> >> >> Please give more details.
> >> >>
> >>
> https://github.com/apache/wicket/blob/master/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/AtmosphereBehavior.java#L51
> >> >> doesn't implement IResourceListener, so it seems you do something
> >> custom.
> >> >>
> >> >> Just implementing IResourceListener doesn't mean anything to Wicket.
> >> >> You need to create a callback url with
> >> >>
> >>
> org.apache.wicket.Component#urlFor(org.apache.wicket.RequestListenerInterface,
> >> >> org.apache.wicket.request.mapper.parameter.PageParameters) and use it
> >> >> somehow to invoke
> >> org.apache.wicket.IResourceListener#onResourceRequested
> >> >>
> >> >>
> >> >> Martin Grigorov
> >> >> Wicket Training and Consulting
> >> >> https://twitter.com/mtgrigorov
> >> >>
> >> >> On Wed, Dec 10, 2014 at 11:45 AM, Daniel Stoch <
> daniel.stoch@gmail.com>
> >> >> wrote:
> >> >>
> >> >>> Is it possible to invoke this listener manually, or maybe this is a
> >> >>> generally a bad practise?
> >> >>>
> >> >>> --
> >> >>> Daniel
> >> >>>
> >> >>> > On 9 gru 2014, at 12:24, Daniel Stoch <da...@gmail.com>
> >> wrote:
> >> >>> >
> >> >>> > Hi,
> >> >>> >
> >> >>> > I have a behavior which implements IResourceListener
> >> >>> > (AtmosphereBehavior). The problem is when this behavior is added
> to
> >> >>> > page during ajax request (eg. some panel is dynamically added to
> >> page)
> >> >>> > - then onResourceRequested is not invoked for page. So when using
> >> >>> > AtmosphereBehavior the suspended connection from the client is not
> >> >>> > registered.
> >> >>> >
> >> >>> > How should I solve this problem: how and when call this
> >> >>> > onResourceRequested method?
> >> >>> >
> >> >>> > --
> >> >>> > Best regards,
> >> >>> > Daniel
> >> >>>
> >> >>>
> ---------------------------------------------------------------------
> >> >>> 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
> >>
> >>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: How to call onResourceRequested for page behavior in ajax update (Atmosphere related)

Posted by Daniel Stoch <da...@gmail.com>.
On Fri, Dec 12, 2014 at 11:38 AM, Martin Grigorov <mg...@apache.org> wrote:
> I see it is a bit ugly, but oh well... this is how it works now.
>
> in YourComponent#renderHead():
>
> AtmosphereBehavior atmo =
> getPage().getBehaviors(AtmosphereBehavior.class).get(0);
> CharSequence callbackUrl = atmo.getCallbackUrl();
> headerResponse.render(OnDomReadyHeaderItem.forScript("Wicket.Ajax.get({u:
> "+callbackUrl+"})"));

Thanks, it works.
But I call whole atmo.renderHead(page, response); method.

>
> You may need to use some flag to make sure this happens once per page
> instance. Otherwise every re-render of such component will initialize a new
> web socket connection (or whatever fallback you may use)
>

Hmmm, do we really need this check if I call whole atmo.renderHead method?

Thanks for your help.

--
Daniel


> Martin Grigorov
> Wicket Training and Consulting
> https://twitter.com/mtgrigorov
>
> On Fri, Dec 12, 2014 at 11:36 AM, Daniel Stoch <da...@gmail.com>
> wrote:
>
>> Hi,
>>
>> Ok, I think I didn't described a problem well.
>>
>> When you add a component which subscribes some events, then
>> AtmosphereBehavior is added to page. But the wicketAtmosphere JS
>> callback is registered inside AtmosphereBehavior.renderHead() method,
>> so only (I think) when the whole page is rendered. When you add a
>> component using ajax, then this code (renderHead) is not called, so
>> events are not broadcasted to client: because page is not registered
>> in EventBus and does not have atmosphere resource assigned.
>>
>> So maybe my original question should be: how to invode this JS
>> callback from AtmosphereBehavior.renderHead in ajax requests?
>>
>> --
>> Daniel
>>
>> On Wed, Dec 10, 2014 at 12:19 PM, Daniel Stoch <da...@gmail.com>
>> wrote:
>> > Hi,
>> >
>> > It seems that I am using an older version of AtmosphereBehavior which
>> > implements IResourceListener. Since 6.17.0 this implementation was
>> > removed and the code is moved to onRequest() method.
>> > So I must check a newer version, maybe my problem is solved.
>> >
>> > Thanks for a tip!
>> >
>> > --
>> > Daniel
>> >
>> > On Wed, Dec 10, 2014 at 11:03 AM, Martin Grigorov <mg...@apache.org>
>> wrote:
>> >> Hi,
>> >>
>> >> Please give more details.
>> >>
>> https://github.com/apache/wicket/blob/master/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/AtmosphereBehavior.java#L51
>> >> doesn't implement IResourceListener, so it seems you do something
>> custom.
>> >>
>> >> Just implementing IResourceListener doesn't mean anything to Wicket.
>> >> You need to create a callback url with
>> >>
>> org.apache.wicket.Component#urlFor(org.apache.wicket.RequestListenerInterface,
>> >> org.apache.wicket.request.mapper.parameter.PageParameters) and use it
>> >> somehow to invoke
>> org.apache.wicket.IResourceListener#onResourceRequested
>> >>
>> >>
>> >> Martin Grigorov
>> >> Wicket Training and Consulting
>> >> https://twitter.com/mtgrigorov
>> >>
>> >> On Wed, Dec 10, 2014 at 11:45 AM, Daniel Stoch <da...@gmail.com>
>> >> wrote:
>> >>
>> >>> Is it possible to invoke this listener manually, or maybe this is a
>> >>> generally a bad practise?
>> >>>
>> >>> --
>> >>> Daniel
>> >>>
>> >>> > On 9 gru 2014, at 12:24, Daniel Stoch <da...@gmail.com>
>> wrote:
>> >>> >
>> >>> > Hi,
>> >>> >
>> >>> > I have a behavior which implements IResourceListener
>> >>> > (AtmosphereBehavior). The problem is when this behavior is added to
>> >>> > page during ajax request (eg. some panel is dynamically added to
>> page)
>> >>> > - then onResourceRequested is not invoked for page. So when using
>> >>> > AtmosphereBehavior the suspended connection from the client is not
>> >>> > registered.
>> >>> >
>> >>> > How should I solve this problem: how and when call this
>> >>> > onResourceRequested method?
>> >>> >
>> >>> > --
>> >>> > Best regards,
>> >>> > Daniel
>> >>>
>> >>> ---------------------------------------------------------------------
>> >>> 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
>>
>>

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


Re: How to call onResourceRequested for page behavior in ajax update (Atmosphere related)

Posted by Martin Grigorov <mg...@apache.org>.
I see it is a bit ugly, but oh well... this is how it works now.

in YourComponent#renderHead():

AtmosphereBehavior atmo =
getPage().getBehaviors(AtmosphereBehavior.class).get(0);
CharSequence callbackUrl = atmo.getCallbackUrl();
headerResponse.render(OnDomReadyHeaderItem.forScript("Wicket.Ajax.get({u:
"+callbackUrl+"})"));

You may need to use some flag to make sure this happens once per page
instance. Otherwise every re-render of such component will initialize a new
web socket connection (or whatever fallback you may use)

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

On Fri, Dec 12, 2014 at 11:36 AM, Daniel Stoch <da...@gmail.com>
wrote:

> Hi,
>
> Ok, I think I didn't described a problem well.
>
> When you add a component which subscribes some events, then
> AtmosphereBehavior is added to page. But the wicketAtmosphere JS
> callback is registered inside AtmosphereBehavior.renderHead() method,
> so only (I think) when the whole page is rendered. When you add a
> component using ajax, then this code (renderHead) is not called, so
> events are not broadcasted to client: because page is not registered
> in EventBus and does not have atmosphere resource assigned.
>
> So maybe my original question should be: how to invode this JS
> callback from AtmosphereBehavior.renderHead in ajax requests?
>
> --
> Daniel
>
> On Wed, Dec 10, 2014 at 12:19 PM, Daniel Stoch <da...@gmail.com>
> wrote:
> > Hi,
> >
> > It seems that I am using an older version of AtmosphereBehavior which
> > implements IResourceListener. Since 6.17.0 this implementation was
> > removed and the code is moved to onRequest() method.
> > So I must check a newer version, maybe my problem is solved.
> >
> > Thanks for a tip!
> >
> > --
> > Daniel
> >
> > On Wed, Dec 10, 2014 at 11:03 AM, Martin Grigorov <mg...@apache.org>
> wrote:
> >> Hi,
> >>
> >> Please give more details.
> >>
> https://github.com/apache/wicket/blob/master/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/AtmosphereBehavior.java#L51
> >> doesn't implement IResourceListener, so it seems you do something
> custom.
> >>
> >> Just implementing IResourceListener doesn't mean anything to Wicket.
> >> You need to create a callback url with
> >>
> org.apache.wicket.Component#urlFor(org.apache.wicket.RequestListenerInterface,
> >> org.apache.wicket.request.mapper.parameter.PageParameters) and use it
> >> somehow to invoke
> org.apache.wicket.IResourceListener#onResourceRequested
> >>
> >>
> >> Martin Grigorov
> >> Wicket Training and Consulting
> >> https://twitter.com/mtgrigorov
> >>
> >> On Wed, Dec 10, 2014 at 11:45 AM, Daniel Stoch <da...@gmail.com>
> >> wrote:
> >>
> >>> Is it possible to invoke this listener manually, or maybe this is a
> >>> generally a bad practise?
> >>>
> >>> --
> >>> Daniel
> >>>
> >>> > On 9 gru 2014, at 12:24, Daniel Stoch <da...@gmail.com>
> wrote:
> >>> >
> >>> > Hi,
> >>> >
> >>> > I have a behavior which implements IResourceListener
> >>> > (AtmosphereBehavior). The problem is when this behavior is added to
> >>> > page during ajax request (eg. some panel is dynamically added to
> page)
> >>> > - then onResourceRequested is not invoked for page. So when using
> >>> > AtmosphereBehavior the suspended connection from the client is not
> >>> > registered.
> >>> >
> >>> > How should I solve this problem: how and when call this
> >>> > onResourceRequested method?
> >>> >
> >>> > --
> >>> > Best regards,
> >>> > Daniel
> >>>
> >>> ---------------------------------------------------------------------
> >>> 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: How to call onResourceRequested for page behavior in ajax update (Atmosphere related)

Posted by Daniel Stoch <da...@gmail.com>.
Hi,

Ok, I think I didn't described a problem well.

When you add a component which subscribes some events, then
AtmosphereBehavior is added to page. But the wicketAtmosphere JS
callback is registered inside AtmosphereBehavior.renderHead() method,
so only (I think) when the whole page is rendered. When you add a
component using ajax, then this code (renderHead) is not called, so
events are not broadcasted to client: because page is not registered
in EventBus and does not have atmosphere resource assigned.

So maybe my original question should be: how to invode this JS
callback from AtmosphereBehavior.renderHead in ajax requests?

--
Daniel

On Wed, Dec 10, 2014 at 12:19 PM, Daniel Stoch <da...@gmail.com> wrote:
> Hi,
>
> It seems that I am using an older version of AtmosphereBehavior which
> implements IResourceListener. Since 6.17.0 this implementation was
> removed and the code is moved to onRequest() method.
> So I must check a newer version, maybe my problem is solved.
>
> Thanks for a tip!
>
> --
> Daniel
>
> On Wed, Dec 10, 2014 at 11:03 AM, Martin Grigorov <mg...@apache.org> wrote:
>> Hi,
>>
>> Please give more details.
>> https://github.com/apache/wicket/blob/master/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/AtmosphereBehavior.java#L51
>> doesn't implement IResourceListener, so it seems you do something custom.
>>
>> Just implementing IResourceListener doesn't mean anything to Wicket.
>> You need to create a callback url with
>> org.apache.wicket.Component#urlFor(org.apache.wicket.RequestListenerInterface,
>> org.apache.wicket.request.mapper.parameter.PageParameters) and use it
>> somehow to invoke org.apache.wicket.IResourceListener#onResourceRequested
>>
>>
>> Martin Grigorov
>> Wicket Training and Consulting
>> https://twitter.com/mtgrigorov
>>
>> On Wed, Dec 10, 2014 at 11:45 AM, Daniel Stoch <da...@gmail.com>
>> wrote:
>>
>>> Is it possible to invoke this listener manually, or maybe this is a
>>> generally a bad practise?
>>>
>>> --
>>> Daniel
>>>
>>> > On 9 gru 2014, at 12:24, Daniel Stoch <da...@gmail.com> wrote:
>>> >
>>> > Hi,
>>> >
>>> > I have a behavior which implements IResourceListener
>>> > (AtmosphereBehavior). The problem is when this behavior is added to
>>> > page during ajax request (eg. some panel is dynamically added to page)
>>> > - then onResourceRequested is not invoked for page. So when using
>>> > AtmosphereBehavior the suspended connection from the client is not
>>> > registered.
>>> >
>>> > How should I solve this problem: how and when call this
>>> > onResourceRequested method?
>>> >
>>> > --
>>> > Best regards,
>>> > Daniel
>>>
>>> ---------------------------------------------------------------------
>>> 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: How to call onResourceRequested for page behavior in ajax update (Atmosphere related)

Posted by Daniel Stoch <da...@gmail.com>.
Hi,

It seems that I am using an older version of AtmosphereBehavior which
implements IResourceListener. Since 6.17.0 this implementation was
removed and the code is moved to onRequest() method.
So I must check a newer version, maybe my problem is solved.

Thanks for a tip!

--
Daniel

On Wed, Dec 10, 2014 at 11:03 AM, Martin Grigorov <mg...@apache.org> wrote:
> Hi,
>
> Please give more details.
> https://github.com/apache/wicket/blob/master/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/AtmosphereBehavior.java#L51
> doesn't implement IResourceListener, so it seems you do something custom.
>
> Just implementing IResourceListener doesn't mean anything to Wicket.
> You need to create a callback url with
> org.apache.wicket.Component#urlFor(org.apache.wicket.RequestListenerInterface,
> org.apache.wicket.request.mapper.parameter.PageParameters) and use it
> somehow to invoke org.apache.wicket.IResourceListener#onResourceRequested
>
>
> Martin Grigorov
> Wicket Training and Consulting
> https://twitter.com/mtgrigorov
>
> On Wed, Dec 10, 2014 at 11:45 AM, Daniel Stoch <da...@gmail.com>
> wrote:
>
>> Is it possible to invoke this listener manually, or maybe this is a
>> generally a bad practise?
>>
>> --
>> Daniel
>>
>> > On 9 gru 2014, at 12:24, Daniel Stoch <da...@gmail.com> wrote:
>> >
>> > Hi,
>> >
>> > I have a behavior which implements IResourceListener
>> > (AtmosphereBehavior). The problem is when this behavior is added to
>> > page during ajax request (eg. some panel is dynamically added to page)
>> > - then onResourceRequested is not invoked for page. So when using
>> > AtmosphereBehavior the suspended connection from the client is not
>> > registered.
>> >
>> > How should I solve this problem: how and when call this
>> > onResourceRequested method?
>> >
>> > --
>> > Best regards,
>> > Daniel
>>
>> ---------------------------------------------------------------------
>> 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: How to call onResourceRequested for page behavior in ajax update (Atmosphere related)

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

Please give more details.
https://github.com/apache/wicket/blob/master/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/AtmosphereBehavior.java#L51
doesn't implement IResourceListener, so it seems you do something custom.

Just implementing IResourceListener doesn't mean anything to Wicket.
You need to create a callback url with
org.apache.wicket.Component#urlFor(org.apache.wicket.RequestListenerInterface,
org.apache.wicket.request.mapper.parameter.PageParameters) and use it
somehow to invoke org.apache.wicket.IResourceListener#onResourceRequested


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

On Wed, Dec 10, 2014 at 11:45 AM, Daniel Stoch <da...@gmail.com>
wrote:

> Is it possible to invoke this listener manually, or maybe this is a
> generally a bad practise?
>
> --
> Daniel
>
> > On 9 gru 2014, at 12:24, Daniel Stoch <da...@gmail.com> wrote:
> >
> > Hi,
> >
> > I have a behavior which implements IResourceListener
> > (AtmosphereBehavior). The problem is when this behavior is added to
> > page during ajax request (eg. some panel is dynamically added to page)
> > - then onResourceRequested is not invoked for page. So when using
> > AtmosphereBehavior the suspended connection from the client is not
> > registered.
> >
> > How should I solve this problem: how and when call this
> > onResourceRequested method?
> >
> > --
> > Best regards,
> > Daniel
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: How to call onResourceRequested for page behavior in ajax update (Atmosphere related)

Posted by Daniel Stoch <da...@gmail.com>.
Is it possible to invoke this listener manually, or maybe this is a generally a bad practise?

--
Daniel

> On 9 gru 2014, at 12:24, Daniel Stoch <da...@gmail.com> wrote:
> 
> Hi,
> 
> I have a behavior which implements IResourceListener
> (AtmosphereBehavior). The problem is when this behavior is added to
> page during ajax request (eg. some panel is dynamically added to page)
> - then onResourceRequested is not invoked for page. So when using
> AtmosphereBehavior the suspended connection from the client is not
> registered.
> 
> How should I solve this problem: how and when call this
> onResourceRequested method?
> 
> --
> Best regards,
> Daniel

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