将列表添加到数据表格中。

huangapple go评论148阅读模式
英文:

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&lt;Profil&gt; listProfil = new ListView&lt;Profil&gt;(&quot;listProfils&quot;, profils) {
    protected void populateItem(ListItem&lt;Profil&gt; item) {
        Profil tmpProfil = item.getModelObject();
        item.add(new Label(&quot;libelle&quot;, tmpProfil.getLibelle()));
        item.add( new ListView(&quot;listChamps&quot;, tmpProfil.getChamps()) {
            protected void populateItem(ListItem item) {
                item.add(new Label(&quot;libelleChamps&quot;, item.getModel()));
            }
        });
    }
});

And the associate HTML template :

&lt;tr wicket:id=&quot;listProfils&quot;&gt;
    &lt;div class=&quot;row&quot;&gt;
        &lt;td class=&quot;col-xs-4 col-md-3 col-lg-3 text&quot;&gt;
            &lt;span wicket:id=&quot;libelle&quot;&gt;&lt;/span&gt;
        &lt;/td&gt;
        &lt;td class=&quot;col-xs-7 col-md-8 col-lg-8 text&quot; colspan=&quot;3&quot;&gt;
            &lt;span wicket:id=&quot;listChamps&quot;&gt;
                &lt;span wicket:id=&quot;libelleChamps&quot; 
                class=&quot;label label-default badge badge-tag&quot; &gt;Champs&lt;/span&gt;
            &lt;/span&gt;
        &lt;/td&gt;
    &lt;/div&gt;
&lt;/tr &gt;

答案2

得分: 0

以下是翻译好的部分:

HTML

<table wicket:id="yourWicketIdOfDataTableObject">[table]
</table>

JAVA

一个POJO(pojoObject),代表表格中的每个元素(o regiser

一个DataProviderdataProviderObject)类,继承自SortableDataProvider<pojoObject, String>

您需要根据您的需求重写iterator()size()model()方法。

一个List<IColumn<pojoObject,String>> columnsObject

上述对象将表示表格的列。

您可以如下添加列:

columnsObject.add(new PropertyColumn<pojoObject,String>(new Model<String>("nameOfTheColum"), pojoObjectPropertyName))

一个DefaultDataTabletableObject):

DataTable<pojoObject, String> = new DefaultDataTable("yourWicketIdOfDataTableObject", columnsObject, dataProviderObject, NumOfColumns)

上述对象将表示表格。

正如您所看到的,pojoObjectcolumnsObjectdataProviderObject包装,最终这两者将被tableObject包装。您的数组将在dataProviderObjectiterator()方法中访问,因为它需要检索列表的迭代器;代表实际列表中每个元素的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

&lt;table wicket:id=&quot;yourWicketIdOfDataTableObject&quot;&gt;[table]
&lt;/table&gt;

JAVA

A POJO (pojoObject) that represents each element (o regiser) of your table

A DataProvider (dataProviderObject) class that extends from SortableDataProvider&lt;pojoObject, String&gt;

You need to override the iterator(), size() and model() methods according to your needs.

A List&lt;IColumn&lt;pojoObject,String&gt;&gt; columnsObject

The above object will represent the colums of your table.

You could add columns as follows:

columnsObject.add(new PropertyColumn&lt;pojoObject,String&gt;(new Model&lt;String&gt;(&quot;nameOfTheColum&quot;),pojoObjectPropertyName))

A DefaultDataTable tableObject:

DataTable&lt;pojoObject, String&gt; = new DefaultDataTable(&quot;yourWicketIdOfDataTableObject&quot;, 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.

huangapple
  • 本文由 发表于 2020年7月22日 17:48:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/63031428.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定