Hi, On Fri, May 3, 2013 at 11:42 AM, Martijn Dashorst < martijn.dasho...@gmail.com> wrote:
> Would it be something for 7.x to make this more straightforward? Not sure > how to accomplish that from the top of my head, but it would be quite nice > to have this out-of-the-box. > I'm experimenting with JS event delegation in branch "event-delegating-behavior". I've pushed a new AjaxEventBehavior that "collects" the Ajax attributes for all AjaxEventBehaviors in the children components of the host. This way there is just one JavaScript binding for all children of the host component and in the same time each child can still have its own ajax attributes (this is a real life requirement). There are few (identified) problems though: 1) if a child component is bound to an <a> element then it will fire non-Ajax request (because there is no JS binding that would usually prevent the default behavior). So <a> should be avoided and submitting components (like AjaxButton) will break at the moment. 2) the server side code is a bit slower because now each AjaxEventBehavior needs to check whether there is EventDelegationBehavior somewhere in the parents. There is an optimization with a MetaDataKey on the page for this problem, so it is not much slower. We may look for further optimizations later. The new behavior can be seen at: https://git-wip-us.apache.org/repos/asf/wicket/repo?p=wicket.git;a=commitdiff;h=ccf4ca1b25c5b485dc61c9642d625dde331b3a52 Usage: java: List<Integer> items = new ArrayList<Integer>(); for (int i = 1; i < 100;i++) { items.add(i); } ListView<Integer> listView = new ListView<Integer>("items", items) { @Override protected void populateItem(final ListItem<Integer> item) { Label link = new Label("link", item.getModel()); item.add(link); link.add(new AjaxEventBehavior("click") { @Override public void onEvent(AjaxRequestTarget target) { System.err.println("clicked item: " + item.getModelObject()); } }); } }; listView.setReuseItems(true); WebMarkupContainer container = new WebMarkupContainer("container"); container.add(new EventDelegatingBehavior("click")); container.add(listView); add(container); markup: <div wicket:id="container"> <div wicket:id="items"> <span wicket:id="link"></span> </div> </div> The main problem I see is AjaxButton. It can be solved by checking the host component of the inner AjaxEventBehavior#renderHead() but it is ugly. What do you think about this approach ? > Martijn > > On Fri, May 3, 2013 at 9:51 AM, Martin Grigorov <mgrigo...@apache.org > >wrote: > > > Hi, > > > > There are many articles in the web about "javascript event delegation". > > Here is one of them: http://davidwalsh.name/event-delegate > > > > The idea is that you should use AjaxEventBehavior on the table component > > without using AjaxLink or any other Ajax component/behavior for the > > components in the cells. > > The cells and rows can have data-xyz attributes with their specific data. > > When a cell is clicked AjaxCallListener can collect the related data from > > the data- attributes and send it to the server. The #onClick() method can > > process the posted data or just broadcast it with Wicket event to the > > children components so they can process it themselves. > > > > This pattern is not so straithforward as using AjaxLink but it indeed > makes > > a difference in the performance, especially in IE family. > > > > > > > > On Fri, May 3, 2013 at 12:15 AM, Nick Pratt <nbpr...@gmail.com> wrote: > > > > > Any demos of this with Wicket form components or simple click > listeners ? > > > > > > I'd much rather a repeater have a single listener for grouped events > (or > > > maybe at the column level for tables) > > > > > > N > > > On May 2, 2013 6:10 PM, "Dan Retzlaff" <dretzl...@gmail.com> wrote: > > > > > > > Martin-G elaborated a bit on this last year: > > > > > > > > > > > > > > http://mail-archives.apache.org/mod_mbox/wicket-users/201209.mbox/%3ccamomwmqdf3ytlstb_kbnvn9t1pump_-+npdtmtvyt+ac6ec...@mail.gmail.com%3E > > > > > > > > I think the gist is that you can avoid attaching listeners to each > > child > > > > with a single listener on the parent with enough smarts to figure out > > > which > > > > child generated the event. > > > > > > > > > > > > On Thu, May 2, 2013 at 3:25 PM, Martin Dietze <d...@fh-wedel.de> > wrote: > > > > > > > > > Than you for your help! > > > > > > > > > > On Thu, May 02, 2013, Martin Grigorov wrote: > > > > > > > > > > > > long blocks of Javascript code executed at "domready". > > > > > > > > > > > > > > > > > > > This depends on how many Ajax components/behaviors you have in > your > > > > page > > > > > > and how many OnDomReadyHeaderItems are contributed. > > > > > > > > > > > > If you use JavaScript event delegation with Wicket Ajax Behavior > > that > > > > > > broadcasts events then you can decrease this dramatically. > > > > > > > > > > That sounds interesting, but - forgive me my ignorance - this is > > > > > the first time I hear about this kind of thing. Can you hint me > > > > > at some example? > > > > > > > > > > Cheers, > > > > > > > > > > M'bert > > > > > > > > > > -- > > > > > ----------- / http://herbert.the-little-red-haired-girl.org / > > > > > ------------- > > > > > =+= > > > > > Katz' Law: Man and nations will act rationally when all other > > > > > possibilities have been exhausted. > > > > > > > > > > > --------------------------------------------------------------------- > > > > > To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org > > > > > For additional commands, e-mail: users-h...@wicket.apache.org > > > > > > > > > > > > > > > > > > > > > > > > > -- > > Martin Grigorov > > Wicket Training & Consulting > > http://jWeekend.com <http://jweekend.com/> > > > > > > -- > Become a Wicket expert, learn from the best: http://wicketinaction.com >