Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wicket and complex Ajax scenarios

Tags:

ajax

wicket

When a screen has multiple interacting Ajax controls and you want to control the visibility of components to react to these controls (so that you only display what makes sense in any given situation), calling target.addComponent() manually on everything you want to update is getting cumbersome and isn't very maintainable.

Eventually the web of onClick and onUpdate callbacks can reach a point where adding a new component to the screen is getting much harder than it's supposed to be.

What are the commonly used strategies (or even libraries if such a thing exists) to avoid this build-up of complexity?

Update: Thank you for your answers, I found all of them very useful, but I can only accept one. Sorry.

like image 967
biziclop Avatar asked Nov 28 '22 03:11

biziclop


2 Answers

In Wicket 1.5 there is an event bus. Each component has onEvent(Object payload) method. With component.send() you can broadcast events and each component can check the payload (e.g. UserJoinedEvent object) and decide whether it wants to participate in the current Ajax response. See http://www.wicket-library.com/wicket-examples/events/ for a simple demo.

like image 89
martin-g Avatar answered Dec 25 '22 10:12

martin-g


You could add structural components such as WebMarkupContainers, when you add this to the AjaxTarget everything contained in it will also get updated. This allows you to update groups of components in a single line.

like image 40
mark-cs Avatar answered Dec 25 '22 10:12

mark-cs