code for ListViewPanel.java":-
class ListViewPanel extends Panel {
public ListViewPanel (String id) {
// created a list of ListViewBean object
List<ListViewBean> list = new ArrayList();
/*
* Here we are populating the list with some "ListViewBean" objects..
* You can populate the list dynamically with list of "ListViewBean" objects according to your application requirement.
*/
list.add(new ListViewBean(1,"abc"));
list.add(new ListViewBean(2,"xyz"));
list.add(new ListViewBean(3,"def"));
list.add(new ListViewBean(4,"jkl"));
/* created list view here with wicket:id="listView" by which this will be *rendered in markup.As second parameter we pass the above list of "ListViewBean" *object which contains data for list view.
*/
ListView listView = new ListView("listView", list)
{
/*
* overriding the populateItem() method of "ListView" class here.
*/
protected void populateItem(ListItem item)
{
/* getting the "ListViewBean" object by calling getModelObject() of * "ListItem" class .Just like an iterator it iterates over all * object of "ListViewBean" under list.
*/
ListViewBean listViewBean = (ListViewBean )item.getModelObject();
/*
* added labels for all required columns of list view
*/
item.add(new Label("id", listViewBean .getId()));
item.add(new Label("name", listViewBean .getName()));
}
};
//added list view to panel here
add(listView);
}
}
Now create markup file for "ListViewPanel".
Code for ListViewPanel.html":-
<wicket:panel>
<table width="100%" >
<tr>
<th>ID</th>
<th>Name</th>
</tr>
<tr wicket:id="listView">
<td><span wicket:id="id"></span></td>
<td><span wicket:id="name"></span></td>
</tr>
</table>
</wicket:panel>
By this way you can create a "ListView" with as many as columns required. In the same way you can also use "PageableListView" instead of "ListView".The benefit of "PageableListView" is that it also provides you a default pagination if number of rows in list view is more than passed number of rows in the constructor of "PageableListView". Constructor of "PageableListView" contains one more parameter "int row" compare to simple "ListView" discussed above.
Hope above tip will be helpful for those who is working with wicket or will get a chace to play around Wicket in future.