Kaleidoscope and complex scenarios Ajax

If there are several interacting Ajax controls on the screen, and you want to control the visibility of components to respond to these controls (so that you only display what makes sense in any given situation target.addComponent() manually calling target.addComponent() on everything you want the update becomes cumbersome and not very convenient to maintain.

In the end, onClick and onUpdate can reach a point where adding a new component to the screen becomes much more difficult than anticipated.

What are the commonly used strategies (or even libraries if such a thing exists) to avoid this complex process?

Update: Thanks for your answers, I found them very useful, but I can only accept them. Unfortunately.

+4
source share
5 answers

Well, how many components are we talking about here? ten? 20? Hundreds?

For up to twenty or so, you can have a state controller that controls which components should be displayed. This controller sets the visible field of the component model, and you always add all the components to your requests, which are processed by the controller. In ajax event components, you simply redirect the controller descriptor method.

For a really large number of components that have too much payload for good performance, you can use javascript libraries like jQuery to show shows and hide things from the client.

+2
source

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

+9
source

You can add structural components such as WebMarkupContainer s, when you add this to AjaxTarget, everything contained in it will also be updated. This allows you to update component groups on a single line.

+8
source

When I create components for the page, I try to add them to composite arrays:

 Component[] pageComponents = { new TextField<String>("Field1"), new TextField<String>("Field2"), new TextField<String>("Field3") } 

As in Wicket 1.5, add functions accept array parameters [1]. Therefore, elements can be added to a page or goal as follows:

 add(pageComponents); target.add(pageComponents); 

Components can then be grouped based on what you want to update together.

[1] http://www.jarvana.com/jarvana/view/org/apache/wicket/wicket/1.5-M3/wicket-1.5-M3-javadoc.jar!/org/apache/wicket/ajax/AjaxRequestTarget. html

+3
source

I am currently using some kind of modified Observer-Pattern to simulate an event bus in Wicket 1.4.

My pages act as an observable observer, because my components do not know each other and are reused in different combinations on several pages. Whenever one component receives an Ajax event, which can affect other components, it calls a method on its page with the event object and target ajax. The page calls a similar method for all components that have registered for this kind of event, and each component can decide, based on the provided event-object, if and how it should respond and can join the target.

The same can be archived using a wicket visitor. I donโ€™t know which one is better, but I think itโ€™s basically a matter of taste.

+2
source

All Articles