Wicket 数据表的扩展

发布于 2024-11-18 13:20:13 字数 5365 浏览 1 评论 0原文

我们可以在另一个 DataTable 中扩展一个 DataTable 吗?

我的场景是我想构建一个名为 BaseTableDataTable ,其中包含三列:idname、<代码>颜色。我想构建另外两个名为 Table1 的表,它扩展了 BaseTable 并具有另一列:sizeTable2 也扩展了 BaseTable 并具有另一个复选框列。

可以做这样的事情吗?如果可能的话,您能给我一些例子或指南吗?

更新

感谢您的帮助!这似乎是我想要的答案,但我确实按照你所说的做了,但最终得到了这个错误:

WicketMessage: The component(s) below failed to render. A common problem is that you have added a component in code but forgot to reference it in the markup (thus the component will never be rendered).

1. [MarkupContainer [Component id = dt_basecontract_list]]
2. [MarkupContainer [Component id = body]]
3. [MarkupContainer [Component id = rows]]
4. [MarkupContainer [Component id = 1]]
5. [MarkupContainer [Component id = cells]]
6. [MarkupContainer [Component id = 1]]
7. [Component id = cell]
8. [MarkupContainer [Component id = 2]]
9. [Component id = cell]
10. [MarkupContainer [Component id = 3]]
11. [MarkupContainer [Component id = cell]]
12. [MarkupContainer [Component id = detail]]
13. [MarkupContainer [Component id = delete]]

如果你需要那里的信息..

基类:ContractBasePanel

// A Base Contract DataTable Panel
public class ContractBasePanel extends Panel  {

    // Inject the ApplicationFacade
    @EJB(name="applicationFacade")
    private ApplicationFacadeLocal applicationFacade;

    public ContractBasePanel(String id, ApplicationFacadeLocal applicationFacade) {
        super(id);
        add(new DefaultDataTable<Contract>("dt_basecontract_list", getColumns(), new ContractProvider(applicationFacade), 10));
    }

    protected List<IColumn<Contract>> getColumns(){
        List<IColumn<Contract>> columns = new ArrayList<IColumn<Contract>>();
        columns.add(new PropertyColumn<Contract>(new Model<String>("ContractIdentifier"), "contractIdentifier"));
        columns.add(new PropertyColumn<Contract>(new Model<String>("Assigned To"), "customer.name"));
        return columns;
    }
}

Inherited Class : ContractModelRootPanel

// A Panel which displays a DataTable of contract
public class ContractModelRootPanel extends ContractBasePanel  {

    // Inject the ApplicationFacade
    @EJB(name="applicationFacade")
    private ApplicationFacadeLocal applicationFacade;

    // Represent the Contract Object selected by clicking "detail" or "delete" link
    private Contract contractSelected;

    public ContractModelRootPanel(String id, ApplicationFacadeLocal applicationFacade) {
        super(id, applicationFacade);
        add(new DefaultDataTable<Contract>("dt_contract_list", getColumns(), new ContractProvider(applicationFacade), 10));
    }

    class ActionPanel extends Panel
    {
        public ActionPanel(String id, IModel<Contract> model)
        {
            super(id, model);
            add(new Link("detail")
            {
                @Override
                public void onClick()
                {
                    // get Contract object which contains only contract identifier
                    contractSelected = (Contract)getParent().getDefaultModelObject();
                    PageParameters pageParameters = new PageParameters();
                    pageParameters.add("contractIdentifier", contractSelected.getContractIdentifier());

                    // handle the displays message if the contract has no owner
                    if(contractSelected.getCustomer() != null)  {
                        pageParameters.add("customerName", contractSelected.getCustomer().getName());
                    }
                    else  {
                        pageParameters.add("customerName", "-Not Bound to Any Customer-");
                    }
                    setResponsePage(ContractDetail.class, pageParameters);
                }
            });

            add(new Link("delete")
            {
                @Override
                public void onClick()
                {
                    // get Contract object which contains only contract identifier
                    contractSelected = (Contract)getParent().getDefaultModelObject();
                    applicationFacade.deleteContract(contractSelected.getContractIdentifier());
                    RequestCycle rc = RequestCycle.get();
                    rc.setResponsePage(HomePage.class);
                }
            });
        }
    }

    @Override
    protected List<IColumn<Contract>> getColumns() {
        List<IColumn<Contract>> columns = super.getColumns();
        // column for "detail" and "delete" link
        columns.add(new AbstractColumn<Contract>(new Model<String>("Edits"))
                {
                    public void populateItem(Item<ICellPopulator<Contract>> cellItem, String componentId,
                        IModel<Contract> model)
                    {
                        cellItem.add(new ActionPanel(componentId, model));
                    }
                });
        return columns;
    }
}

两个类的 HTML 是相同的,除了 wicket id ,它是 dt_basecontract_listdt_contract_list

这个错误从何而来?

Can we extend a DataTable in another DataTable?

My scenario is I would like to build a DataTable called BaseTable which contains three columns: id, name, color. I want to build another two tables called Table1 which extends BaseTable and has another column: size; and Table2 which also extends BaseTable and has another checkbox column.

Is it possible to do something like this? If possible, can you give me some example or guidelines?

Update

Thank you for your help! It seems to be the answer I want but I did exactly what you said but I ended up get this error:

WicketMessage: The component(s) below failed to render. A common problem is that you have added a component in code but forgot to reference it in the markup (thus the component will never be rendered).

1. [MarkupContainer [Component id = dt_basecontract_list]]
2. [MarkupContainer [Component id = body]]
3. [MarkupContainer [Component id = rows]]
4. [MarkupContainer [Component id = 1]]
5. [MarkupContainer [Component id = cells]]
6. [MarkupContainer [Component id = 1]]
7. [Component id = cell]
8. [MarkupContainer [Component id = 2]]
9. [Component id = cell]
10. [MarkupContainer [Component id = 3]]
11. [MarkupContainer [Component id = cell]]
12. [MarkupContainer [Component id = detail]]
13. [MarkupContainer [Component id = delete]]

In case you need there information..

Base Class : ContractBasePanel

// A Base Contract DataTable Panel
public class ContractBasePanel extends Panel  {

    // Inject the ApplicationFacade
    @EJB(name="applicationFacade")
    private ApplicationFacadeLocal applicationFacade;

    public ContractBasePanel(String id, ApplicationFacadeLocal applicationFacade) {
        super(id);
        add(new DefaultDataTable<Contract>("dt_basecontract_list", getColumns(), new ContractProvider(applicationFacade), 10));
    }

    protected List<IColumn<Contract>> getColumns(){
        List<IColumn<Contract>> columns = new ArrayList<IColumn<Contract>>();
        columns.add(new PropertyColumn<Contract>(new Model<String>("ContractIdentifier"), "contractIdentifier"));
        columns.add(new PropertyColumn<Contract>(new Model<String>("Assigned To"), "customer.name"));
        return columns;
    }
}

Inherited Class : ContractModelRootPanel

// A Panel which displays a DataTable of contract
public class ContractModelRootPanel extends ContractBasePanel  {

    // Inject the ApplicationFacade
    @EJB(name="applicationFacade")
    private ApplicationFacadeLocal applicationFacade;

    // Represent the Contract Object selected by clicking "detail" or "delete" link
    private Contract contractSelected;

    public ContractModelRootPanel(String id, ApplicationFacadeLocal applicationFacade) {
        super(id, applicationFacade);
        add(new DefaultDataTable<Contract>("dt_contract_list", getColumns(), new ContractProvider(applicationFacade), 10));
    }

    class ActionPanel extends Panel
    {
        public ActionPanel(String id, IModel<Contract> model)
        {
            super(id, model);
            add(new Link("detail")
            {
                @Override
                public void onClick()
                {
                    // get Contract object which contains only contract identifier
                    contractSelected = (Contract)getParent().getDefaultModelObject();
                    PageParameters pageParameters = new PageParameters();
                    pageParameters.add("contractIdentifier", contractSelected.getContractIdentifier());

                    // handle the displays message if the contract has no owner
                    if(contractSelected.getCustomer() != null)  {
                        pageParameters.add("customerName", contractSelected.getCustomer().getName());
                    }
                    else  {
                        pageParameters.add("customerName", "-Not Bound to Any Customer-");
                    }
                    setResponsePage(ContractDetail.class, pageParameters);
                }
            });

            add(new Link("delete")
            {
                @Override
                public void onClick()
                {
                    // get Contract object which contains only contract identifier
                    contractSelected = (Contract)getParent().getDefaultModelObject();
                    applicationFacade.deleteContract(contractSelected.getContractIdentifier());
                    RequestCycle rc = RequestCycle.get();
                    rc.setResponsePage(HomePage.class);
                }
            });
        }
    }

    @Override
    protected List<IColumn<Contract>> getColumns() {
        List<IColumn<Contract>> columns = super.getColumns();
        // column for "detail" and "delete" link
        columns.add(new AbstractColumn<Contract>(new Model<String>("Edits"))
                {
                    public void populateItem(Item<ICellPopulator<Contract>> cellItem, String componentId,
                        IModel<Contract> model)
                    {
                        cellItem.add(new ActionPanel(componentId, model));
                    }
                });
        return columns;
    }
}

HTML of both classes are the same except the wicket id which is dt_basecontract_list and dt_contract_list.

Where does this error come from?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

骄兵必败 2024-11-25 13:20:13

下面是一个示例:

BaseDataTable.java:

private DataTable<T> table;
private SortableDataProvider<T> provider;

public BaseDataTable(String id, IModel model){
super(id, model);
provider = new ....;
table = new DataTable<T>("datatable", getColumns(), provider, rowsPerPage);
add(table);
}

protected IColumn<T>[] getColumns(){
return new IColumn[]{
new PropertyColumn<Account>(new StringResourceModel("id",
                        null), null, "id"),
new PropertyColumn<Account>(new StringResourceModel("name",
                        null), null, "name"),
new PropertyColumn<Account>(new StringResourceModel("color",
                        null), null, "color")
}
}

其他扩展 BaseDataTable 的表,您必须重写 getColumns() 方法并在第一行中调用 super.getColumns()重写的方法。

希望我有所帮助!

Here is an example for you:

BaseDataTable.java:

private DataTable<T> table;
private SortableDataProvider<T> provider;

public BaseDataTable(String id, IModel model){
super(id, model);
provider = new ....;
table = new DataTable<T>("datatable", getColumns(), provider, rowsPerPage);
add(table);
}

protected IColumn<T>[] getColumns(){
return new IColumn[]{
new PropertyColumn<Account>(new StringResourceModel("id",
                        null), null, "id"),
new PropertyColumn<Account>(new StringResourceModel("name",
                        null), null, "name"),
new PropertyColumn<Account>(new StringResourceModel("color",
                        null), null, "color")
}
}

The other tables, that extends BaseDataTable, you have to override the getColumns() method and call super.getColumns() in the first line of the overridden method.

Hope I helped!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文