Topic
1 reply Latest Post - ‏2012-04-04T15:37:01Z by bnorwood
bnorwood
bnorwood
3 Posts
ACCEPTED ANSWER

Pinned topic pagecode and clearing hx:dataTableEx

‏2012-03-29T16:41:33Z |
I have a page that contains a list of Reports in a hx:dataTableEx control. I use pagecode for the JSF bean to hold this.

From the JSP

<hx:dataTableEx var="incidents" border="0" cellpadding="2" cellspacing="0" columnClasses="columnClass1" headerClass="headerClass" footerClass="footerClass" rowClasses="rowClass1, rowClass2" styleClass="openIncidentsDataTableEx" id="openIncidentTableId" rows="10" value="#{pc_YourOpenReports.reportList}">

//various columns, etc

</hx:dataTableEx>

In the pagecode java file:

public DataModel getReportList()
{
if (reportDataTable == null)
{
reportDataTable = new ListDataModel();
try
{
IncidentReportApplication app = IncidentReportApplication.getInstance();
String aceId = app.calculateACEID((HttpServletRequest) getFacesContext().getExternalContext().getRequest());
reportDataTable.setWrappedData(new IncidentReportDAO().getOpenIncidentsForUser(aceId));
}
catch (Exception e)
{
log.error("Error getting report list for user: " + e.getMessage(), e);
}

}

return reportDataTable;
}
This all works fine but my problem comes in if a user adds a new report. For a new report I need to null out the reportList in the pageCode bean and have it reloads from the database. I've tried manually setting reportDataTable = null; after adding a new report and also removing the pc_YourOpenReports bean manually from the session, but I always see the old data without the new report added.

Any ideas?
Updated on 2012-04-04T15:37:01Z at 2012-04-04T15:37:01Z by bnorwood
  • bnorwood
    bnorwood
    3 Posts
    ACCEPTED ANSWER

    Re: pagecode and clearing hx:dataTableEx

    ‏2012-04-04T15:37:01Z  in response to bnorwood
    I figured out what the problem was. It was actually a JPA issue and not a JSF issue. In the JPA association, I had the following:
    //bi-directional many-to-one association to Host
    @OneToMany(mappedBy="report", fetch=FetchType.EAGER)
    private Set<Host> hosts;

    This set of hosts was what drove the DataTableEx on the JSP. When I was removing or editing a host, I was never going back and updating the hosts set in the JPA entity. I was assuming that the "JPA Magic" was going to do it for me, but I was sadly mistaken.