reRender not working after DB is changed
bossy Jul 6, 2009 6:31 PMHello,
I have two tables with a many-to-many relationship (Building(buildId,buildName)
and Features(featId,feaName)). The implementation is via a link table.
I add/remove features to a building entity using the following page:
<h:panelGrid columns="2" rowClasses="prop" width="100%" >
<s:div><a:form styleClass="association" id="featuresChildren" >
<rich:dataTable id="featuresTable" value="#{buildingHome.features}" var="_features" >
<rich:column sortBy="#{_features.featCodeDisplayText}">
<f:facet name="header">Building Features</f:facet>
<h:outputText value="#{_features.featCodeDisplayText}"/>
</rich:column>
<rich:column >
<a:commandLink value="Remove"
id="removeFeat" action="#{buildingFeaturesHome.removeFeature()}" >
<f:param name="featCode" value="#{_features.featCode}"/>
<a:support event="oncomplete" reRender="featuresTable" />
</a:commandLink>
</rich:column>
</rich:dataTable>
</a:form></s:div>
<s:div><a:form id="buildingFeatures" styleClass="edit" >
<s:decorate id="featCodeField" template="layout/edit.xhtml">
<ui:define name="label">Features</ui:define>
<h:selectOneMenu value="#{buildingFeaturesHome.instance.id.featCode}">
<s:selectItems value="#{featuresList.resultList}" var="_f" label="#{_f.featCodeDisplayText}"
itemValue="#{_f.featCode}" />
</h:selectOneMenu>
</s:decorate>
<a:commandLink id="save" value="Add" action="#{buildingFeaturesHome.addFeature()}" >
<f:param name="featCode" value="#{buildingFeaturesHome.instance.id.featCode}"/>
<a:support event="oncomplete" reRender="featuresTable" />
</a:commandLink>
</a:form></s:div>
</h:panelGrid>
My BuildingFeaturesHome class has the following two methods:
@RequestParameter
String featCode;
public String removeFeature()
{
String ret="";
this.setId(new BuildingFeaturesId(buildingHome.getInstance().getBuildId(),featCode));
ret=this.remove();
buildingHome.getEntityManager().refresh(buildingHome.getInstance());
return ret;
}
public String addFeature()
{
if(this.getInstance().getId().getFeatCode()==null) return "";
if(this.isManaged())
{
this.setInstance(new BuildingFeatures(new BuildingFeaturesId(BuildingHome.getInstance().getBuildId(),this.getInstance().getId().getFeatCode())));
}
else
{
this.getInstance().getId().setBuildId(BuildingHome.getInstance().getBuildId());
}
String ret=this.persist();
buildingHome.getEntityManager().refresh(buildingHome.getInstance());
return ret;
}
It all works fine with one exception - the refresh/reRender on the Delete commandLink does not refresh the list with the current features, although the DB is updated.
There are some exceptions to this - before I add any new features during a conversation the refresh works. But even in this case when I delete the last feature - the refresh again does not work.
I do realise that this has something to do with the managed/transient state of the entities, but I can't work out why the refresh/reRender is affected by this.
Any help will be highly apreciated.
Thanks.