Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache Wicket Repeaters: an overview

Tags:

java

wicket

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?

like image 369
Stijn Geukens Avatar asked Oct 13 '11 07:10

Stijn Geukens


People also ask

What is Apache Wicket?

Apache Wicket, commonly referred to as Wicket, is a component-based web application framework for the Java programming language conceptually similar to JavaServer Faces and Tapestry. It was originally written by Jonathan Locke in April 2004.

What are pages and components in wicket?

Pages and Components in Wicket are real Java objects that support encapsulation, inheritance and events. Create high level components with ease and bundle its stylesheets, JavaScript and other resources into one reusable package.

What license does wicket use?

Since its inception in 2004 Wicket has been an open source project and remains available under one of the most permissive licenses: the Apache Software License. Pages and Components in Wicket are real Java objects that support encapsulation, inheritance and events.

What are the configuration files to learn in wicket?

Wicket aims for simplicity. There are no configuration files to learn in Wicket. Wicket is a simple class library with a consistent approach to component structure.


1 Answers

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!

like image 184
jbrookover Avatar answered Sep 20 '22 19:09

jbrookover