2 Replies Latest reply on Feb 17, 2007 5:40 PM by pmuir

    @DataModel doesn't load the first time

    james_hays

      Hey guys, I have an interesting issue with @DataModel. I don't believe I have changed anything after I had this working when I moved to Seam 1.1.6

      What I have is a search page that takes some data on page a, enters an action listener, runs a query against the database and outjects the value through @DataModel to be used on page b. The values are coming back from the database and populating the instance value correctly, but my xhtml won't see the data until I hit refresh page 5.

      Here's a few code snippets.

      @Name("search")
      @Stateless
      public class SearchAction implements Search
       {
       @Logger
       private Log log;
      
       @PersistenceContext
       private EntityManager em;
      
       @Out
       @In
       ProfileRecord profileRecord;
      
       @DataModel
       private List<ProfileRecord> searchResults;
      
       @DataModelSelection("searchResults")
       private ProfileRecord currentProfileRecord;
      
       public String basicSearch()
       {
       log.info("Running Basic Search");
       ProfileRecord pr = new ProfileRecord();
       pr.setWaNumber(profileRecord.getWaNumber());
       pr.setProposalNumber(profileRecord.getProposalNumber());
       profileRecord = pr;
       searchResults = em.createQuery("Select pr from ProfileRecord pr where pr.waNumber LIKE :waNumber")
       .setParameter("waNumber", pr.getWaNumber() + "%")
       .getResultList();
       log.info("Profile Records Found: " + searchResults.size());
       return "/detailedSearch.seam";
       }
      
      

       <ui:define name="content">
       <div class="tabularData">
       <h:dataTable cellpadding="0" cellspacing="0" value="#{searchResults}" var="currentProfileRecord" rules="all" width="100%">
       <h:column>
       <f:facet name="header">WA #</f:facet>
       <h:outputText value="#{currentProfileRecord.waNumber}" />
       </h:column>
       <h:column>
       <f:facet name="header">SBU</f:facet>
       ???
       </h:column>
      


      When this page loads the first time, the table with the DataModel is empty. as soon as I refresh the page, it's there. I've run the debugger and the list is populated the first time through.

      Any thoughts on what might be causing this?

        • 1. Re: @DataModel doesn't load the first time
          james_hays

          To add a bit more clarification after working on this some more, I can't get it to work with any previous Seam builds either. It also will not populate the table after a refresh, but will populate it if I call an action that either returns null or has a void return type. I had this working at one point and it's a simple concept. Am I missing something simple?

          • 2. Re: @DataModel doesn't load the first time
            pmuir

            Sounds like for some reason the datamodel isn't getting outjected straight away. Perhaps try outputting a logical outcome and specifying a redirect navigation rule *might* help. Otherwise you could try explicitly clearing the searchResults varialbe in basicSearch() - or try using an EntityQuery which should work ootb.