framework:entity-home with framework:entity-query for simple admin
andrewwheeler Jun 9, 2010 7:18 PMInstead of writing endless java boilerplate code handle simple reference data administration I want to use entity-home and entity-query in components.xml.
<framework:entity-query name="identificationTypes" ejbql="from IdentificationType order by description" scope="event"/> <framework:entity-home entity-class="sample.model.party.IdentificationType" name="identificationTypeHome" scope="event"/>
The edit page is rather simple with a form and a clickable list in a datatable. The list invokes the page with the primary key of the entity as a parameter.
<h:form id="form">
<rich:panel header="Identification Type" id="identificationTypePanel">
<s:decorate id="descriptionDecoration" template="/layout/edit.xhtml">
<ui:define name="label">Description:</ui:define>
<h:inputText id="description" size="50" maxlength="50" value="#{identificationTypeHome.instance.description}" required="true">
<a:support event="onblur" reRender="descriptionDecoration" bypassUpdates="true" ajaxSingle="true" limitToList="true"/>
</h:inputText>
</s:decorate>
<s:decorate id="expiresDecoration" template="/layout/edit.xhtml">
<ui:define name="label">Expires:</ui:define>
<h:selectBooleanCheckbox value="#{identificationTypeHome.instance.expires}"/>
</s:decorate>
<div style="clear:both">
<span class="required">*</span>
required fields
</div>
</rich:panel>
<div class="action-buttons">
<h:commandButton id="save" value="Save" action="#{identificationTypeHome.persist}" rendered="#{!identificationTypeHome.managed}"/>
<h:commandButton id="update" value="Save" action="#{identificationTypeHome.update}" rendered="#{identificationTypeHome.managed}"/>
<h:commandButton id="delete" value="Delete" action="#{identificationTypeHome.remove}" rendered="#{identificationTypeHome.managed}"/>
<h:commandButton id="clear" value="Clear" action="#{identificationTypeHome.clearInstance}"/>
<s:button id="cancel" value="Cancel" propagation="end" action="home.authorised"/>
</div>
<rich:dataTable id="identificationTypeList" var="i"
value="#{identificationTypes.resultList}"
rendered="#{not empty identificationTypes.resultList}">
<h:column>
<f:facet name="header">Description</f:facet>
<s:link value="#{i.description}">
<f:param name="id" value="#{i.identificationTypeId}"/>
</s:link>
</h:column>
</rich:dataTable>
</h:form>
The problem is that when creating a new entry using identificationTypeHome.persist the entity is not added to the list. I can see the the list is retrieved before the persist in the console window.
As the identificationTypeHome.persist is in the Invoke Application phase and the entity-query should be invoked in the Render Response phase this must be persistence flushing problem. The entityManager probably does not flush until the end of the Render Response phase.
Adding
<begin-conversation join="true" flush-mode="commit"/>
to my identificationType.page.xml does not make a difference (I don't really need to start a conversation!).
There is no problem with identificationTypeHome.update - the new values appear in the list.
Any thoughts on how to force the flush?