0 Replies Latest reply on Mar 9, 2009 5:50 AM by Thai Dang Vu

    DataModel annotation and ajax refresh

    Thai Dang Vu Apprentice

      I don't understand why the db was hit for every single ajax request.


      This is my SFSB:


      @Stateful
      @Name("employees")
      @Scope(ScopeType.CONVERSATION)         // cannot be page-scoped
      public class EmployeesImpl implements Employees {
          @Logger private Log log;
      
          @PersistenceContext private EntityManager entityManager;
      
          @DataModel(value="allEmployees", scope=ScopeType.PAGE) protected List<Employee> allEmployees;
      
          private Employee selectedEmployee;
      
          public void findAllEmployees() {
              allEmployees = entityManager.createQuery("select e from Employee e").getResultList();
          }
      
          public void selectEmployee(Employee e) {
              selectedEmployee = e;
          }
      
          public void selectEmployee1() {
              log.debug("hic hic hic");
          }


      My test.xhtml:


      <a4j:form>
          <h:dataTable value="#{allEmployees}" var="employee" width="840">
              <h:column>
                  <f:facet name="header">ID</f:facet>
                  <a4j:commandLink value="#{employee.id}" action="#{employees.selectEmployee1}"/>
                  <h:outputText value="&#160;(call a non-parameter method)" style="font-style: italic;"/>
              </h:column>
              <h:column>
                  <f:facet name="header">First Name</f:facet>
                  <a4j:commandLink value="#{employee.firstName}" action="#{employees.selectEmployee(employee)}"/>
              </h:column>
          </h:dataTable>
      </a4j:form>
      


      My pages.xml:


      <page view-id="/test.xhtml" action="#{employees.findAllEmployees}" />



      Clicking on both <a4j:commandLink> causes a hit to the db.


      I think, those clicks create ajax requests only. So, why is the method findAllEmployees executed for every single request?