Search code examples
javaasynchronoustapestry

Tapestry Grid inside Zone update error


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!


Solution

  • 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)