3 Replies Latest reply on Mar 15, 2011 8:06 AM by ssachtleben.ssachtleben.gmail.com

    backing bean is invoked three times

    vdeminico
      Hi,
      I'm observing this strange behaviour in my simple app... I have this xhtml fragment in my page:


      "
      <h:dataTable var="_member" value="#{utenteController.utentiList}">
               <h:column>
                  <f:facet name="header">Name</f:facet>
                  #{_member.nome}
               </h:column>
               <h:column>
                  <f:facet name="header">Cognome</f:facet>
                  #{_member.cognome}
               </h:column>
               <h:column>
                  <f:facet name="header">Username</f:facet>
                  #{_member.username}
               </h:column>
      </h:dataTable>
      "

      and this is my backing bean:
      "
      @Named
      public class UtenteController {
           @EJB UtenteService utenteService;
           private final Logger logger = Logger.getLogger(UtenteController.class);
           
           public List<Utente> getUtentiList()
           {
                logger.info("Invoco in Controller");
                return utenteService.retriveUtenteList();
           }
      }
      "

      Looking at log file I observe that the controller is invoked three times... why?

      Thanks,
      Valerio.
        • 1. Re: backing bean is invoked three times
          lightguard

          This is more of a JSF question. I think everyone that's done JSF development has seen this before. I'm honestly not sure why, but I suspect it has something to do with restoring the view, building up the component tree and rendering. Perhaps someone with more JSF in-depth knowledge will also respond.

          • 2. Re: backing bean is invoked three times
            ratking

            You should change the bean as the following:


            @Named
            public class UtenteController {
                @EJB UtenteService utenteService;
                private List<Utente> utenteList;
                
                private final Logger logger = Logger.getLogger(UtenteController.class);
                public List<Utente> getUtentiList()
                {
                    logger.info("Invoco in Controller");
                    if (utenteList == null)
                    {
                        utenteList = utenteService.retriveUtenteList();
                    }
                return utenteList;
                }
            }



            How-to: avoid method or getter to be called several times by caching result
            My Link

            • 3. Re: backing bean is invoked three times
              ssachtleben.ssachtleben.gmail.com

              I think Jason is correct. If you also use the rendered tag also it will be called 6 times.