Reputation: 97
I'm trying to accomplish a simple task: delete a record from database, update Grid, which source attribute points to user list, downloaded from DB. I have a Grid component inside tml:
<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>
Inside of a page class, I have:
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();
}
But when I press the delete button, i get the following Tapestry error:
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)
While the partial changing of a Grid row works well (didn't included that code), I cannot reload the whole zone with Grid component. Can anyone point me the direction, to accomplish dynamic delete action of a user? Any help would be really appreciated!
Upvotes: 1
Views: 787
Reputation: 97
After fixing problem with model initialization, I've got the following working code:
<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>
Getting model:
public BeanModel getAdminTableModel() {
BeanModel<Admin> model;
model = beanModelSource.createDisplayModel(Admin.class, messages);
...
return model;
}
Getting source:
public GridDataSource getAdminsSource() {
return new HibernateGridDataSource(session, Admin.class);
}
So, pressing delete, I get an update of currently displayed page of grid data source. Hope this will help someone)
Upvotes: 1
Reputation: 891
I see several issues with that code:
Grid's add
:
"... is only used when a default model is created automatically." https://tapestry.apache.org/5.4/apidocs/org/apache/tapestry5/corelib/components/Grid.html
but at the same time you're supplying custom model for the grid via model="adminTableModel"
.
Syntax error in context of the ActionLink
: context="${currAdmin.}"
. There's an extra dot (.
) in the end.
Upvotes: 0