As a good practice in Wicket, to build a Table in HTML that is being fed from a List, you need the following elements:
HTML
<table wicket:id="yourWicketIdOfDataTableObject">[table]
</table>
JAVA
A POJO (pojoObject
) that represents each element (o regiser
) of your table
A DataProvider (dataProviderObject
) class that extends from SortableDataProvider<pojoObject, String>
You need to override the iterator()
, size()
and model()
methods according to your needs.
A List<IColumn<pojoObject,String>> columnsObject
The above object will represent the colums of your table.
You could add columns as follows:
columnsObject.add(new PropertyColumn<pojoObject,String>(new Model<String>("nameOfTheColum"),pojoObjectPropertyName))
A DefaultDataTable tableObject
:
DataTable<pojoObject, String> = new DefaultDataTable("yourWicketIdOfDataTableObject", columnsObject, dataProviderObject, NumOfColumns)
The above object will represent the table.
As you might see pojoObject
wraped by columnsObject
and dataProviderObject
, and these two will be wrapped by tableObject
at the end. Your array will be accessed in the iterator()
method of the dataProviderObject
, because it needs to retrieve the iterator of the list; The pojoObject
that represent the each element of your actual list will be necessary (in case you don't have one yet)
At the end, you only need add tableObject
in their Wicket Parent, as any other Wicket Component.
- abc
- def
`, or even an inner table.
– martin-g Jul 23 '20 at 07:21