You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Nelson Segura <ns...@gmail.com> on 2011/10/01 01:18:25 UTC

On component added to ajax request target

I wonder if anyone has ideas on how to add a component to an
AjaxRequestTarget if another related component is added to it.
I am thinking about my Ajax List, there are several ways it can be
added to a request target: sorting, filtering, paging, etc.
I have another components that displays data related to the list, but
displayed outside the list. Is there a way I can detect that the list
is being refreshed using Ajax, and add those other components to the
target?

-Nelson

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


Re: On component added to ajax request target

Posted by Nelson Segura <ns...@gmail.com>.
I did something in the order of what you suggested:
Created a new AjaxRequestTarget sub class

public class MyAjaxRequestTarget extends AjaxRequestTarget {
....
public void addComponent(Component component) {
        super.addComponent(component);
        // see if this component has related components that are
interesting in being
        // ajax refreshed when this component is refreshed.
        if (component instanceof IHasRelatedAjaxComponent) {
            List<Component> relatedComponentList =
((IHasRelatedAjaxComponent) component).getRelatedAjaxComponents();
            if (relatedComponentList != null &&
!relatedComponentList.isEmpty()) {
                for (Component c : relatedComponentList) {
                    // add only if the new component is not in the hierarchy
                    if (!getComponents().contains(c)) {
                        addComponent(c);
                    }
                }
            }
        }

}

Any feedback from the list is welcome!

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


Re: On component added to ajax request target

Posted by Dan Retzlaff <dr...@gmail.com>.
You could override WebApplication#newAjaxRequestTarget to add a listener to
each target. You can look at AjaxRequestTarget#getComponents() to see if
your list is there, and maybe add more stuff. Sounds messy though, since
that's an application-wide listener. Maybe you could generate an event if
any of the ART's components implement some marker interface, and have your
other components consume the event and add themselves if necessary.

On Fri, Sep 30, 2011 at 4:18 PM, Nelson Segura <ns...@gmail.com> wrote:

> I wonder if anyone has ideas on how to add a component to an
> AjaxRequestTarget if another related component is added to it.
> I am thinking about my Ajax List, there are several ways it can be
> added to a request target: sorting, filtering, paging, etc.
> I have another components that displays data related to the list, but
> displayed outside the list. Is there a way I can detect that the list
> is being refreshed using Ajax, and add those other components to the
> target?
>
> -Nelson
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>