0 Replies Latest reply on Mar 9, 2009 5:50 AM by dxxvi

    DataModel annotation and ajax refresh

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

      This is my SFSB:

      @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:

          <h:dataTable value="#{allEmployees}" var="employee" width="840">
                  <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;"/>
                  <f:facet name="header">First Name</f:facet>
                  <a4j:commandLink value="#{employee.firstName}" action="#{employees.selectEmployee(employee)}"/>

      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?