Wicket 数据表的扩展
我们可以在另一个 DataTable
中扩展一个 DataTable
吗?
我的场景是我想构建一个名为 BaseTable
的 DataTable
,其中包含三列:id
、name
、<代码>颜色。我想构建另外两个名为 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;
}
}
两个类的 HTML 是相同的,除了 wicket id ,它是 dt_basecontract_list
和 dt_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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
下面是一个示例:
BaseDataTable.java:
其他扩展 BaseDataTable 的表,您必须重写 getColumns() 方法并在第一行中调用 super.getColumns()重写的方法。
希望我有所帮助!
Here is an example for you:
BaseDataTable.java:
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!