我想添加到我的所有树节点编辑并创建新的子链接,但我收到错误,即id cell的子节点已经存在。
columns.add(new AbstractColumn<Classification, String>(Model.of("")) {
private static final long serialVersionUID = 1L;
@Override
public void populateItem(Item<ICellPopulator<Classification>> cellItem, String componentId,
final IModel<Classification> rowModel) {
cellItem.add(new TreeLinkPanel(componentId, rowModel, tree));
}
});
columns.add(new AbstractColumn<Classification, String>(Model.of("")) {
private static final long serialVersionUID = 1L;
@Override
public void populateItem(Item<ICellPopulator<Classification>> cellItem, String componentId,
final IModel<Classification> rowModel) {
cellItem.add(new ClassificationNewLink(componentId, rowModel, tree));
}
});
现在我这样做,但这个很难看。我不能为我的专栏写标题。有关如何将两个链接放在同一列中的任何想法吗?
答案 0 :(得分:4)
单元格项目只是一个具有wicket id的组件,所以你不能真正添加它多次。
最简单的方法是创建一个包含您要添加的任何组件的面板或片段(例如,两个链接)。
您的代码示例:
columns.add(new AbstractColumn<Classification, String>(Model.of("")) {
private static final long serialVersionUID = 1L;
@Override
public void populateItem(Item<ICellPopulator<Classification>> cellItem, String componentId, final IModel<Classification> rowModel) {
// your model
cellItem.add(new MyCellPanel(componentId, rowModel, tree));
}
});
MyCellPanel类示例:
public class MyCellPanel extends Panel {
MyCellPanel(String componentId, final IModel<Classification>rowModel, final Tree tree) {
super(componentId, rowModel);
add(new TreeLinkPanel("treeLink", rowModel, tree); {
add(new ClassificationNewLink("classificationNewLink", rowModel, tree); {
}
}
MyCellPanel.html示例:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<wicket:panel xmlns:wicket="http://wicket.apache.org">
<div wicket:id="treeLink">tree link</div>
<a wicket:id="classificationNewLink">classification link</a>
</wicket:panel>
</body>
答案 1 :(得分:0)
这只是一个疯狂的猜测,但如果您尝试仅填充一次该列,该怎么办:
columns.add(new AbstractColumn<Classification, String>(Model.of("")) {
private static final long serialVersionUID = 1L;
@Override
public void populateItem(Item<ICellPopulator<Classification>> cellItem, String componentId,final IModel<Classification> rowModel) {
// your model
cellItem.add(new TreeLinkPanel("treeLinkPanelId", rowModel, tree));
// the add link
cellItem.add(new ClassificationNewLink("classificationNewLinkId", rowModel, tree));
}
});