0
我們可以在另一個DataTable
中擴展DataTable
嗎?Wicket數據表擴展
我的情況是我想建立一個名爲DataTable
其中BaseTable
包含三列:id
,name
,color
。我想要建立另一個名爲Table1
的表格,它擴展了BaseTable
並且有另一列:size
;和Table2
其中也延伸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;
}
}
除了檢票ID爲dt_basecontract_list
和dt_contract_list
以外,兩個類別的HTML都是相同的。
這個錯誤來自哪裏?
我收到一個錯誤,不知道它從哪裏來。你能幫我嗎? – Dennis
請檢查HTML文件中的標記層次結構。我提供了html文件,我也會檢查它。 – lepike
很少有Java編譯器給出來自構造函數的調用虛擬方法的相關警告。在運行時通常工作正常,但要小心 –