2 Replies Latest reply on Jan 13, 2008 2:05 PM by Gianni

    DataModel changes not reflected in view [possible newbie ign

    Gianni Newbie

      I'm using a session-scope stateful session bean to hold search results in a DataModel - in a similar manner to the booking example.

      I first populate the DataModel by performing an entity query, if I then modify and persist one of the entities from the search results, return to the search page and perform the same search again the changes to the entity are not reflected in the view, my dataTable still displays the original values even though logging shows that the DataModel has been correctly updated.

      private List<Website> websites;
      String letter;
      public void findDomainByLetter() {
       websites = entityManager.createNamedQuery("Website.findByDomainLetter")
       .setParameter("domainName", letter.toLowerCase() + "%")
       .setFirstResult(page * pageSize)

      <ui:repeat value="#{websiteSearch.alphabet}" var="letter">
       <s:link value="#{letter}" action="#{websiteSearch.findDomainByLetter}">
       <f:param name="letter" value="#{letter}"/>
       </s:link> Â 
      <h:dataTable id="websites" value="#{websites}" var="site" rendered="#{websites.rowCount>0}">
       <f:facet name="header"><h:outputText value="#{msgs['website.host-name']}"/></f:facet>
       <s:link action="#{siteManager.editSite}">
       <h:outputText value="#{site.domain.name}"/>
       <f:param name="id" value="#{site.id}"/>

      If I then perform a different search and subsequently repeat the original search the changes are then reflected in the view.

      Could this be some kind of view caching issue or maybe a poor grasp of the jsf lifecycle ..?
      I'd appreciate some suggestions.

        • 1. Re: DataModel changes not reflected in view [possible newbie
          Pete Muir Master

          Performing a search is clicking on a letter in the repeat?

          Let's see how you persist an entity.

          • 2. Re: DataModel changes not reflected in view [possible newbie
            Gianni Newbie

            Yes clicking a letter (A-Z) on the repeat performs the search and then each row of the search results has an edit link which invokes editSite() on a conversation-scoped bean 'siteManager'.

            public class WebsiteManagerBean implements WebsiteManager {
            @In(required = false)
            @Out(required = false)
            private Website website;
            private EntityManager entityManager;
            private boolean editMode;
            private boolean siteFound;
            Integer id;
            public WebsiteManagerBean() {
            public void editSite() {
             this.editMode = true;
             if (!findSite()) {
             log.error("Website not found for id " + id);
            private boolean findSite() {
             if (id == null) {
             return false;
             this.website = entityManager.find(Website.class, id);
             siteFound = (null != website) ? true : false;
             return siteFound;
            public void updateSite() {
             log.info("Updated website details #{website.id}");

            I'm not doing anything particular to persist the changes, clicking 'save' on the edit page invokes updateSite() and the modifications are flushed to the database. I then click a link to return to the search results.

            Initially the search results do not contain the modifications as they are held in the session-scoped bean and I'm not yet updating that when updateSite() is invoked (hence the @RaiseEvent being commented out).

            The thing perplexing me is that when I invoke the original search again it seems to query the database but the changes to the entity do not appear in the search results, even though they are present in the DataModel.