4 Replies Latest reply on Dec 22, 2008 9:00 PM by mrauls

    reRender problem

    msznapka

      Hello,
      I have problem with this simple Ajax example:

      <h:outputText value="outputText" rendered="#{outside1.rendered}"/>
      
      <a4j:commandLink action="#{ajax.increaseCounter}" ajaxSingle="true" reRender="ajaxOutputPanel" value="link"/>
      
      <a4j:outputPanel id="ajaxOutputPanel">
       #{ajax.counter}
      </a4j:outputPanel>
      
      <a4j:repeat value="#{outside2.list}" var="item">
       #{item}
      </a4j:repeat>


      Now, if I click on the ajax link, than the counter is increased and outputPanel shows the new value, BUT the ajax request also calls outside1.rendered and outside2.list! And that is the problem for me, because these outside beans (request scoped) loads data from database, which I dont want during this ajax request.
      The only bean which should be created is Ajax class.
      Does anyone have an idea how to achieve that?

      Working example in Tomcat.

      The rest of the code is here:

      @Name("ajax")
      @Scope(ScopeType.EVENT)
      public class Ajax {
      
       private int counter;
      
       @Create
       public void create() {
       System.out.println("Ajax.create()");
       counter = 0;
       }
      
       public void increaseCounter() {
       System.out.println("Ajax.increaseCounter()");
       counter++;
       }
      
       public int getCounter() {
       System.out.println("Ajax.getCounter()");
       return counter;
       }
      }


      @Name("outside1")
      @Scope(ScopeType.EVENT)
      public class Outside1 {
      
       private boolean rendered;
      
       @Create
       public void create() {
       System.out.println("Outside1.create()");
       rendered = true;
       }
      
       public boolean isRendered() {
       System.out.println("Outside1.isRendered()");
       return rendered;
       }
      
      }


      @Name("outside2")
      @Scope(ScopeType.EVENT)
      public class Outside2 {
      
       private List<Integer> list;
      
       @Create
       public void create() {
       System.out.println("Outside2.create()");
       list = Arrays.asList(1,2,3);
       }
      
       public List<Integer> getList() {
       System.out.println("Outside2.getList()");
       return list;
       }
      
      }


      Possible solution with moving outside beans to higher scope than Event is not acceptable for me.