You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Nick Pratt <nb...@gmail.com> on 2013/11/01 14:45:31 UTC

Component detecting Ajax update

Is there a way for a Component to detect if its been added to an
AjaxRequestTarget?

N

Re: Component detecting Ajax update

Posted by vineet semwal <vi...@gmail.com>.
see AjaxRequestTarget#getComponents()


On Fri, Nov 1, 2013 at 7:15 PM, Nick Pratt <nb...@gmail.com> wrote:

> Is there a way for a Component to detect if its been added to an
> AjaxRequestTarget?
>
> N
>



-- 
regards,

Vineet Semwal

Re: Component detecting Ajax update

Posted by Bas Gooren <ba...@iswd.nl>.
And from within the component itself you can override onEvent and handle 
the event whose payload is an AjaxRequestTarget.
The component can then check if it's in the getComponents() collection 
of said target.

e.g.

@Override
     public void onEvent( IEvent< ? > event )
     {
         Object payload = event.getPayload();

         if( payload instanceof AjaxRequestTarget )
         {
             AjaxRequestTarget target = (AjaxRequestTarget) payload;
             if(target.getComponents().contains(this)) {
                  // your logic goes here
             }
         }
     }

Met vriendelijke groet,
Kind regards,

Bas Gooren

schreef Martin Grigorov op 4-11-2013 8:27:
> Hi,
>
> You can use
> org.apache.wicket.ajax.AjaxRequestTarget.IListener#onBeforeRespond(Map<String,
> Component> map, AjaxRequestTarget) to be notified before ART starts
> preparing its XML response.
> The 'map' contains all already added components.
>
>
>
> On Fri, Nov 1, 2013 at 3:45 PM, Nick Pratt <nb...@gmail.com> wrote:
>
>> Is there a way for a Component to detect if its been added to an
>> AjaxRequestTarget?
>>
>> N
>>


Re: Component detecting Ajax update

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

You can use
org.apache.wicket.ajax.AjaxRequestTarget.IListener#onBeforeRespond(Map<String,
Component> map, AjaxRequestTarget) to be notified before ART starts
preparing its XML response.
The 'map' contains all already added components.



On Fri, Nov 1, 2013 at 3:45 PM, Nick Pratt <nb...@gmail.com> wrote:

> Is there a way for a Component to detect if its been added to an
> AjaxRequestTarget?
>
> N
>

Re: Component detecting Ajax update

Posted by Martin Funk <ma...@gmail.com>.
traveling down the implementations of 

AjaxRequestTarget.add
AjaxRequestHandler public void add(Component... components)

one comes across to:

AbstractAjaxResponse.add((final Component component, final String markupId)

I don't see code that signals the Component that it was added to an AjaxRequestTarget

it just seems to end up in an HashMap of AbstractAjaxResponse

markupIdToComponent.put(markupId, component);


So my guess is, that the component itself can't detect that it was added.

If you are serious about it, maybe deriving form AjaxRequestHandler and than hooking the derived Handler up into the Application might help.

At least the Application has a setter for the AjaxRequestTargetProvider:
	@Override
	protected void internalInit()
	{
[...]
		setAjaxRequestTargetProvider(new DefaultAjaxRequestTargetProvider());
[...}
	}


Though I'm not sure if that is an ok path, maybe someone else has a better idea.

Martin



Am 01.11.2013 um 14:45 schrieb Nick Pratt <nb...@gmail.com>:

> Is there a way for a Component to detect if its been added to an
> AjaxRequestTarget?
> 
> N


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