英文:
Wicket : Add a list to a datatable
问题
我有一个对象列表要在Wicket表格中显示。
这些对象由一个字符串和一个字符串数组组成。
我的问题是,我不知道如何将这个数组添加到我的表格中。其次,我有一些CSS需要应用到数组中的每个字符串,所以它们每个都必须放在不同的div/span/li中。
把所有这些元素都拼接起来并手动添加"div"是否是一个好主意呢?
谢谢你的帮助
英文:
I have a list of object to display in a table with wicket.
Those object are composed of a String and an Array of String.
My problem is that i don't know how to add this array into my table. And second, i have some css that I need to apply to each of my String of the array, so each of them have to be on a different div/span/li.
Can it be a good idea to concatenate all those elements and add the "div" manually ?
Thank you for your help
答案1
得分: 0
我一直痴迷于使用数据表。通过在列表中使用列表,它运行得很好!
JAVA:
ListView<Profil> listProfil = new ListView<Profil>("listProfils", profils) {
protected void populateItem(ListItem<Profil> item) {
Profil tmpProfil = item.getModelObject();
item.add(new Label("libelle", tmpProfil.getLibelle()));
item.add(new ListView("listChamps", tmpProfil.getChamps()) {
protected void populateItem(ListItem item) {
item.add(new Label("libelleChamps", item.getModel()));
}
});
}
});
关联的HTML模板:
<tr wicket:id="listProfils">
<div class="row">
<td class="col-xs-4 col-md-3 col-lg-3 text">
<span wicket:id="libelle"></span>
</td>
<td class="col-xs-7 col-md-8 col-lg-8 text" colspan="3">
<span wicket:id="listChamps">
<span wicket:id="libelleChamps" class="label label-default badge badge-tag">Champs</span>
</span>
</td>
</div>
</tr>
英文:
I have been to obssesed with using a datatable. By using a list in a list it work just fine !
JAVA :
ListView<Profil> listProfil = new ListView<Profil>("listProfils", profils) {
protected void populateItem(ListItem<Profil> item) {
Profil tmpProfil = item.getModelObject();
item.add(new Label("libelle", tmpProfil.getLibelle()));
item.add( new ListView("listChamps", tmpProfil.getChamps()) {
protected void populateItem(ListItem item) {
item.add(new Label("libelleChamps", item.getModel()));
}
});
}
});
And the associate HTML template :
<tr wicket:id="listProfils">
<div class="row">
<td class="col-xs-4 col-md-3 col-lg-3 text">
<span wicket:id="libelle"></span>
</td>
<td class="col-xs-7 col-md-8 col-lg-8 text" colspan="3">
<span wicket:id="listChamps">
<span wicket:id="libelleChamps"
class="label label-default badge badge-tag" >Champs</span>
</span>
</td>
</div>
</tr >
答案2
得分: 0
以下是翻译好的部分:
HTML
<table wicket:id="yourWicketIdOfDataTableObject">[table]
</table>
JAVA
一个POJO(pojoObject
),代表表格中的每个元素(o regiser
)
一个DataProvider
(dataProviderObject
)类,继承自SortableDataProvider<pojoObject, String>
您需要根据您的需求重写iterator()
、size()
和model()
方法。
一个List<IColumn<pojoObject,String>> columnsObject
上述对象将表示表格的列。
您可以如下添加列:
columnsObject.add(new PropertyColumn<pojoObject,String>(new Model<String>("nameOfTheColum"), pojoObjectPropertyName))
一个DefaultDataTable
(tableObject
):
DataTable<pojoObject, String> = new DefaultDataTable("yourWicketIdOfDataTableObject", columnsObject, dataProviderObject, NumOfColumns)
上述对象将表示表格。
正如您所看到的,pojoObject
被columnsObject
和dataProviderObject
包装,最终这两者将被tableObject
包装。您的数组将在dataProviderObject
的iterator()
方法中访问,因为它需要检索列表的迭代器;代表实际列表中每个元素的pojoObject
将是必需的(如果您尚未拥有它)
最后,您只需要将tableObject
添加到其Wicket父组件中,就像任何其他Wicket组件一样。
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论