有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java Wicket在同一列中有两个链接

我想添加到我的所有树节点编辑和创建新的子链接,但我得到一个错误,即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));
        }
    });

现在我正在做这件事,但这件很难看。我不能为我的专栏写标题。有没有办法把两个链接放在同一个专栏里


共 (1) 个答案

  1. # 1 楼答案

    单元格项只是一个具有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); {
    
        }
    
    }
    

    mycell面板。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>