3 Replies Latest reply on Jul 27, 2008 1:40 PM by pmuir

    c:for calls seam el method for each iteration

    chadws

      I am having an issue understanding the way data is processed in JSF using a method executed by the SEAM EL parser. I know this is not an issue with seam or its parser, but with my understanding of JSF and facelets and was wondering if anyone has seen this before and can help me resolve it.


      What I have is a method that I am calling from a Facelets Component. This component is used to load an agenda view of calendar events based on information provided by the page author. The problem is that the method on my bean is being called for every iteration of the loop rather than simply iterating the items returned by the initial call. The following is the Facelets code that displays the information:


      <c:set var="calendarAgenda" value="#{calendarManager.findAgendaItemsByItems(startDate, tps:stringToInteger(numEntries), null, tags)}" />
      <c:set var="agendaKeys" value="#{tps:retrieveMapKeys(calendarAgenda)}" />
      <table>
        <c:forEach var="agendaKey" items="${agendaKeys}">
           <!-- Header Outputs here
          <c:set var="agendaEntries" value="#{tps:retrieveMapValues(calendarAgenda, agendaKey)}" />
          <c:forEach var="agendaEntry" items="${agendaEntries}" varStatus="status">
            <!-- Day Data Outputs Here -->
          </c:forEach>
        </c:forEach>
      </table>
      



      I was under the impression that by calling c:set the values were returned and that the loop would simply iterate the results, but instead I end up with approximately 100 calls to this method. Has anyone seen this before and do you have any suggestions as to what I can do to fix it as I need to increase the performance?

        • 1. Re: c:for calls seam el method for each iteration
          pmuir

          EL/JSF always uses late evaluation and evaluates the EL expression everytime - no workaround I know of

          • 2. Re: c:for calls seam el method for each iteration
            chadws

            Would using a seam bean with a factory work as long as the bean is placed into the request scope?



            For example, make a request for calandarAgenda.getAgenda() and have the factory method lookup the results and store them in the agenda property so that subsequent calls would return the agenda and not recreate it.


            If this sounds feasible what would the appropriate method of setting the parameters on the factory be? or should I look them up from a specified context. My bean will require a date, a minimum number of entries to return and a list of tag names.

            • 3. Re: c:for calls seam el method for each iteration
              pmuir

              Yes, doing expensive work in a getter is an anti pattern - I missed you were doing that. Read the performance section on this website.