Refreshing an Entity in a Nested Conversation
clerum Apr 24, 2009 4:56 PMOK-
I have nested conversation going where I show a list or organizations as the root conversation, then click on a organization and display it's details. From there you start a 2nd nested conversation which add's the site. Once I finish adding the site I use a conversation.endAndRedirect(); to pop the outside conversation and return to the view for the organization.
This page which shows the organization has a datatable listing out all the sites.
<rich:simpleTogglePanel switchType="client" label="Sites" opened="#{organization.sites.size != 0}"> <h:outputText value="No Sites exist" rendered="#{organization.sites.size==0}"/> <rich:dataTable columnClasses="column-center,column-left,column-left,column-left,column-center" width="75%" id="siteList" var="site" value="#{organization.sites}" rendered="#{organization.sites.size != 0}"> <rich:column headerClass="column-center"> <f:facet name="header">Edit Site</f:facet> <s:link value="Edit Site" action="#{siteUtil.findSite()}"> <f:param name="site_id" value="#{site.id}" /> </s:link> </rich:column> <rich:column headerClass="column-left"> <f:facet name="header"><h:outputText styleClass="column-left" value="Name"/></f:facet> <h:outputText value="#{site.name}" /> </rich:column> .. .... </rich:dataTable>
This datatable however isn't getting refreshed with the new site that was added. What approach should I be using to accomplish this? Would this be handled by an EXTENDED PersistenceContext? (I'm only using @In EntityManager em; as I don't really understand the different between it and @PersistenceContext)
How can I refresh the organization entity so that the site list is updated?
import java.io.Serializable; import java.util.Date; import java.util.List; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.OneToMany; import javax.persistence.OrderBy; import javax.persistence.Table; import javax.persistence.Temporal; import javax.persistence.TemporalType; import javax.persistence.Version; import org.hibernate.validator.Length; import org.hibernate.validator.NotNull; import org.jboss.seam.annotations.Name; @Entity @Name("organization") @Table(name="organization") public class Organization implements Serializable { private static final long serialVersionUID = 1L; private long id; private int version; private String name; private String alias; private String msa_version; private int payment_terms; private boolean active; private String sfcode; private Date date_created; private Date date_inactive; private List<User> users; private List<Site> sites; public Organization() {} @GeneratedValue @NotNull @Id public long getId() { return id; } public void setId(long id) { this.id = id; } @Version @NotNull public int getVersion() { return version; } public void setVersion(int version) { this.version = version; } @Length(min=1,max=75) @NotNull public String getName() { return name; } public void setName(String name) { this.name = name; } @Length(min=1,max=75) public String getAlias() { return alias; } public void setAlias(String alias) { this.alias = alias; } public String getMsa_version() { return msa_version; } public void setMsa_version(String msa_version) { this.msa_version = msa_version; } public int getPayment_terms() { return payment_terms; } public void setPayment_terms(int payment_terms) { this.payment_terms = payment_terms; } @NotNull public boolean isActive() { return active; } public void setActive(boolean active) { this.active = active; } @OneToMany(mappedBy="organization") @OrderBy("lastname") public List<User> getUsers() { return users; } public void setUsers(List<User> users) { this.users = users; } @OneToMany(mappedBy="organization") @OrderBy("name") public List<Site> getSites() { return sites; } public void setSites(List<Site> sites) { this.sites = sites; } @Length(min=10,max=10) @NotNull public String getSfcode() { return sfcode; } public void setSfcode(String sfcode) { this.sfcode = sfcode; } @Temporal(TemporalType.DATE) public Date getDate_created() { return date_created; } public void setDate_created(Date date_created) { this.date_created = date_created; } @Temporal(TemporalType.DATE) public Date getDate_inactive() { return date_inactive; } public void setDate_inactive(Date date_inactive) { this.date_inactive = date_inactive; } }