gpt4 book ai didi

java - 如何在 wicket 中嵌套动态表?

转载 作者:行者123 更新时间:2023-11-30 05:50:22 25 4
gpt4 key购买 nike

我正在使用 wicket 来显示表格列表。表的数量和每个表中的行数都是动态的。

我试图保持简单并为每个使用 RepeatingView,并嵌套它们,但 wicket 说:

java.lang.IllegalArgumentException: A child with id 'table' already exists

这是我的Java:

   RepeatingView view = new RepeatingView("listoftables");

for (CCSubscription sub: getCustomer().getSubscriptions()) {

//resource balance table
ResourceBalance[] resBals = sub.getResourceBalances();
if(resBals!=null && resBals.length>0) {
ListView<ResourceBalance> resBalTable = new ListView<ResourceBalance>("table", Arrays.asList(resBals)) {

@Override
protected void populateItem(ListItem<ResourceBalance> item) {
ResourceBalance bal = item.getModelObject();
item.add(new Label("resource", bal.getResource().getName()));
item.add(new Label("balance", bal.getBalance()));
}
};
view.add(resBalTable);
} //end if sub has non-null resource balance

} //end loop through subscriptions

add(view);

我的 html 是:

<ul>
<li wicket:id="listoftables">
<fieldset>
<legend><b>Resource Balances</b>
</legend>
<table class="dataview" style="width:50%">
<thead>
<tr class="headers">
<th>Resource</th>
<th>Balance</th>

</tr>
</thead>
<tr wicket:id="table">
<td>
<span wicket:id="resource"></span>
</td>
<td>
<span wicket:id="balance"></span>
</td>
</tr>
</table>
</fieldset>
<br/>

我承认我可能以错误的方式解决这个问题,但我看不出正确的方法应该是什么。

希望有人能帮忙!?

最佳答案

好的,我开始工作了:

final ListView<CCSubscription> tables = new ListView<CCSubscription>(
"tables", getCustomer().getSubscriptions()) {
@Override
protected void populateItem(ListItem<CCSubscription> item) {
ListView<ResourceBalance> resBalTable = new ListView<ResourceBalance>("listview", Arrays.asList(item.getModel().getObject().getResourceBalances())) {

@Override
protected void populateItem(ListItem<ResourceBalance> item) {
ResourceBalance bal = item.getModelObject();
item.add(new Label("resource", bal.getResource().getName()));
item.add(new Label("balance", bal.getBalance()+""));
}
};
item.add(resBalTable);
}
};

add(tables);

HTML 如下所示:

<span wicket:id="tables">
<fieldset>
<legend><b>Resource Balances</b>
</legend>
<table class="dataview" style="width:50%">
<thead>
<tr class="headers">
<th>Resource</th>
<th>Balance</th>

</tr>
</thead>
<tr wicket:id="listview">
<td>
<span wicket:id="resource"></span>
</td>
<td>
<span wicket:id="balance"></span>
</td>


</tr>
</table>
</fieldset>
<br/>

关于java - 如何在 wicket 中嵌套动态表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14195180/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com