我正在尝试完成一项简单的任务:从数据库中删除记录,更新Grid,哪个源属性指向用户列表,从DB下载。我在tml中有一个Grid组件:
<div t:type="zone" t:id="deleteZone" id="deleteZone">
<table t:type="grid" source="allAdmins" row="currAdmin" empty="blabla" model="adminTableModel"
add="delete,lock">
<p:deleteCell>
<t:actionlink t:id="delete" context="${currAdmin.}" zone="deleteZone">
Delete admin
</t:actionlink> <!--context=""-->
</p:deleteCell>
</table>
</div>
在页面类中,我有:
public List<AUser> getAllAdmins() {
return webHelpService.getAllUsers(true);
}
@InjectComponent
private Zone deleteZone;
Object onActionFromDelete(int code) {
Admins adminToChange = dao.getAdmin(code);
if(code!=0) {
dao.deleteAdmin(adminToChange);
}
return deleteZone.getBody();
}
但是当我按下删除按钮时,我收到以下Tapestry错误:
org.apache.tapestry5.runtime.ComponentEventException: Render queue error in SetupRender.
location: points to line <t:actionlink t:id="delete" context="${currAdmin.code}" zone="deleteZone">
org.apache.tapestry5.ioc.internal.OperationException
location: point to Grid.tml line <thead t:id="columns"/>
java.lang.NullPointerException
org.apache.tapestry5.internal.beaneditor.BeanModelUtils.add(BeanModelUtils.java:74)
org.apache.tapestry5.internal.beaneditor.BeanModelUtils.modify(BeanModelUtils.java:42)
org.apache.tapestry5.corelib.components.Grid.getDataModel(Grid.java:523)
org.apache.tapestry5.corelib.components.GridColumns.setupRender(GridColumns.java:112)
org.apache.tapestry5.corelib.components.GridColumns.setupRender(GridColumns.java)
org.apache.tapestry5.internal.structure.ComponentPageElementImpl$SetupRenderPhase.invokeComponent(ComponentPageElementImpl.java:174)
org.apache.tapestry5.internal.structure.ComponentPageElementImpl$AbstractPhase.invoke(ComponentPageElementImpl.java:133)
org.apache.tapestry5.internal.structure.ComponentPageElementImpl$SetupRenderPhase.render(ComponentPageElementImpl.java:181)
org.apache.tapestry5.internal.services.RenderQueueImpl.run(RenderQueueImpl.java:72)
org.apache.tapestry5.internal.services.PageRenderQueueImpl.render(PageRenderQueueImpl.java:124)
org.apache.tapestry5.internal.services.PageRenderQueueImpl$1.renderMarkup(PageRenderQueueImpl.java:142)
org.apache.tapestry5.internal.services.RenderCommandComponentEventResultProcessor.renderMarkup(RenderCommandComponentEventResultProcessor.java:78)
org.apache.tapestry5.internal.services.PageRenderQueueImpl$Bridge.renderMarkup(PageRenderQueueImpl.java:62)
org.apache.tapestry5.internal.services.PageRenderQueueImpl.renderPartial(PageRenderQueueImpl.java:159)
org.apache.tapestry5.internal.services.PartialMarkupRendererTerminator.renderMarkup(PartialMarkupRendererTerminator.java:45)
org.apache.tapestry5.services.TapestryModule$37.renderMarkup(TapestryModule.java:2141)
虽然Grid行的部分更改效果很好(没有包含该代码),但我无法使用Grid组件重新加载整个区域。 任何人都可以指出方向,完成用户的动态删除操作吗? 任何帮助都会非常感激!
答案 0 :(得分:1)
在修复模型初始化问题后,我得到了以下工作代码:
Advanced Settings
获得模特:
<t:zone t:id="deleteZone" id="deleteZone">
<table t:type="grid" source="adminsSource" rowsPerPage="5" row="currAdmin" inPlace="true" model="adminTableModel" empty="Admins not found" class="t-data-grid table table-bordered">
...
<p:deleteCell>
<t:actionlink t:id="delete" context="currAdmin.code" zone="deleteZone"
${message:delete}
</t:actionlink>
</p:deleteCell>
获取来源:
public BeanModel getAdminTableModel() {
BeanModel<Admin> model;
model = beanModelSource.createDisplayModel(Admin.class, messages);
...
return model;
}
所以,按删除键,我得到当前显示的网格数据源页面的更新。希望这会对某人有所帮助)
答案 1 :(得分:0)
我看到该代码有几个问题:
网格add
:
“...仅在自动创建默认模型时使用。” https://tapestry.apache.org/5.4/apidocs/org/apache/tapestry5/corelib/components/Grid.html
但同时您通过model="adminTableModel"
为网格提供自定义模型。
ActionLink
:context="${currAdmin.}"
的上下文中的语法错误。最后还有一个额外的点(.
)。