Wicket DataTable的扩展

时间:2011-07-01 11:46:51

标签: inheritance datatable wicket

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

我的方案是,我想构建一个名为DataTable的{​​{1}},其中包含三列:BaseTableidname。我想构建另外两个名为color的表,它扩展Table1并有另一列:BaseTable;和size也扩展了Table2,并有另一个复选框列。

有可能做这样的事吗?如果可能的话,你能给我一些例子或指导吗?

更新

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

BaseTable

如果您需要信息..

基类:ContractBasePanel

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]]
除了wicket id // 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; } } dt_basecontract_list之外,

两个类的HTML都是相同的。

这个错误来自哪里?

1 个答案:

答案 0 :(得分:0)

以下是您的示例:

<强> 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()。

希望我帮忙!