Example:
<tbody> <tr wicket:id="rows" class="even"> <td><span wicket:id="id">Test ID</span></td> ...
Though this example is about a HTML table, ListView is not at all limited to HTML tables. Any kind of list can be rendered using ListView.
The related Java code:
add(new ListView<UserDetails>("rows", listData) { public void populateItem(final ListItem<UserDetails> item) { final UserDetails user = item.getModelObject(); item.add(new Label("id", user.getId())); } });
NOTE: When you want to change the default generated markup it is important to realize that the ListView instance itself does not correspond to any markup, however, the generated ListItems do.
This means that methods like {@link #setRenderBodyOnly(boolean)} and{@link #add(org.apache.wicket.behavior.Behavior)} should be invoked on the {@link ListItem}that is given in {@link #populateItem(ListItem)} method.
WARNING: though you can nest ListViews within Forms, you HAVE to set the setReuseItems property to true in order to have validation work properly. By default, setReuseItems is false, which has the effect that ListView replaces all child components by new instances. The idea behind this is that you always render the fresh data, and as people usually use ListViews for displaying read-only lists (at least, that's what we think), this is good default behavior.
However, as the components are replaced before the rendering starts, the search for specific messages for these components fails as they are replaced with other instances. Another problem is that 'wrong' user input is kept as (temporary) instance data of the components. As these components are replaced by new ones, your user will never see the wrong data when setReuseItems is false.
|
|
|
|
|
|