14

Wicket has many implementations of AbstractRepeaters: ListView, DataView, GridView, Loop, PropertyListView etc.

Personally, I find it hard to determine which view would be ideal for which scenario. I usually stick to DataView but that's simply because I'm used to it. Maybe GridView would be better for scenario A, a PropertyListView for B, ....

Is anyone aware of a blog or any tutorial where the differences of the views are explained or anyone who can explain which view is best for which use case?

1 Answer 1

29

Wicket has a lot of additional, trivial classes, which is causing your confusion. Different components are better for different scenarios, but there are a lot of Wicket components for rare cases that don't add any real complexity.

For example, RequiredTextField is an entire class that is equivalent to:

 TextField x = new TextField("text");
 x.setRequired(true);

I presume this stems from an older version where setting required was more complicated, but it's still there to cause some confusion.

Many of your repeaters are similar. PropertyListView just wraps the model in a CompoundPropertyModel, making property expressions easier (see below). However, you could easily make this change yourself.

So, here is my quick summary as I have been unable to find an up-to-date blog post as you've described:

RepeatingView - very useful when you do not have a list or you are adding different types of components (and therefore different internal markup).

ListView - useful if you have a List and you're displaying the whole thing. Sadly, it does not work with other sorted collections.

DataView - useful if you are loading from a Database. Additional methods allow you to easily sort, page, and modify the data set.

PropertyListView - useful if you are simply displaying values via a property expression. Allows you to do

 item.add(new Label("name")); 

instead of

 item.add(new Label("name", new PropertyModel<String>(item.getModel(), "name")))

Loop - useful if you want to repeat an Integer number of times instead of a set list of data. This would be equivalent to a ListView whose model object is a List<Integer> filled with integers from 0 to length

GridView - useful for taking a single list (e.g. 21 strings) and using two sets of markup (inner/outer) to display that list in groups (e.g. a 7x3 grid). It assumes, however, that your markup uses certain wicket:id's, which is not well documented. I think you would be better off with a pair of nested RepeatingView components, which accomplish the same thing.

Hope that helps!

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.