You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Zala Pierre GOUPIL <go...@gmail.com> on 2015/06/22 10:39:52 UTC

AJAX refreshing of complex components (custom, ListViews and the like)

Good morning,


 This not a question that I'd like to ask here, it's rather something which
I once thought about publishing on my blog but as it is a simple solution
to a recurring problem, I post it here, as I haven't got a blog yet. I lack
of time and, to be honest, I have kind of an ill health…


 So, AFAIK on this list, a recurring problem seems to be: how to refresh
complex components, like repeaters, firstly, and how to do that
efficiently, secondly.


 So from the top of my head, here is the general way to do the first thing,
not for repeaters, but in general cases. Ready ?


 Component componentToRefresh = new Component(…);

parent.addOrRemove(componentToRefresh);

target.add(parent);


 It's so useful that I forced myself to learn it by hearth ;-) A good thing
done isn't it?


 Now, let me explain why ListView and other components must be added to the
page that way. I have not read myself that part of the Wicket source code.
But for me, the logic is this :


 When you only write: target.add(componentToRefresh), Wicket looks for an
HTML id in order to refresh the component. BUT if the component has changed
so much that even it's id (generated or provided by you) is not reliable
itself to identify it, what do you do? Fine wicketeers guys, correct me if
I'm wrong but for me, here is why you must in some cases use the parent
component's id. Think about a DataTable! The parent id is stable, not the
cells' ones. Even if it's just an example.


 Now for the second part: how to do that efficiently (in terms of response
times)? Some people, just like me, realized that for a ListView of
potentially lots of data, or at least when it's costly to compute just a
ListView element, it is still not perfect to use the parent. So they
apparently read about the http://wicketinaction.com/ blog themselves and
found a rather clean and efficient way to implement such a component:


 https://github.com/vineetsemwal/quickview


 (And my memory is still OK, apparently ;-)


 I read the documentation mentioned in the link above myself and it was
sufficient to adapt the given syntax to a video game heavily based on
Websockets with Atmosphere (cheers JF Arcand ;-), so I think I won't say
more for the moment.


As we say in France:

Et voilà !

Many thanks for any feedback and: have a lot of fun!


Pierre


-- 
Je n'aime pas seulement ma vie, mais aussi celle des autres.

(Blade Runner)