title: Dynamically rendered JSF 2 content in request scoped - listener not called when in dynamic content
body: <p>I have put my problem case below, which simplifies a real world problem I am having.  By changing the Bean to @SessionScoped I can solve this, but that is really undesirable.  As is @ViewScoped.  I think it should work in @RequestScoped.  My questions are:</p>
  
  <ul>
  <li>Why does JSF need access to <code>#{simpleBean.outerStrings}</code> to invoke the <code>#{simpleBean.processInnerClick()}</code> listener (outerStrings will have died in the previous request)</li>
  <li>What is the best pattern for solving this?</li>
  </ul>
  
  <p>Happy to edit to make clearer - just let me know.</p>
  
  <p><strong>Bean class</strong></p>
  
  <pre><code>import javax.enterprise.context.RequestScoped;
  import javax.enterprise.context.SessionScoped;
  import javax.inject.Named;
  
  @Named
  @RequestScoped
  public class SimpleBean implements Serializable {
  
      private List&lt;String&gt; topLevelStrings = 
                 Arrays.asList("TopLevel1", "TopLevel2");
  
      private List&lt;String&gt; outerStrings;
  
      private List&lt;String&gt; innerStrings;
  
      public void processOuterClick() {
          System.err.println("processOuterClick()");
          outerStrings = Arrays.asList("Outer1", "Outer2", "Outer3");
      }
  
      public void processInnerClick() {
          System.err.println("processInnerClick()");
          innerStrings = Arrays.asList("InnerA", "InnerB", "InnerC");
      }
  
      public List&lt;String&gt; getOuterStrings() {
          return outerStrings;
      }
  
      public List&lt;String&gt; getInnerStrings() {
          return innerStrings;
      }
  
      public List&lt;String&gt; getTopLevelStrings() {
          return topLevelStrings;
      }
  
  }
  </code></pre>
  
  <p><strong>XHTML</strong></p>
  
  <pre><code>&lt;h:form&gt;
  &lt;ui:repeat var="toplevel" value="#{simpleBean.topLevelStrings}"
             id="toplevel_id"&gt;
  &lt;h:commandLink id="toplevel_command"&gt;
  #{toplevel} &lt;br/&gt;
  &lt;f:ajax render="outerlevel_panel" 
          listener="#{simpleBean.processOuterClick()}"/&gt;
  &lt;/h:commandLink&gt;
  &lt;h:panelGroup id="outerlevel_panel"&gt;
  &lt;ui:repeat var="outerLevel" value="#{simpleBean.outerStrings}" 
      id="outerlevel_id"&gt;
  &lt;h:commandLink id="outerlevel_command"&gt;
  #{outerLevel} &lt;br/&gt; 
  &lt;f:ajax listener="#{simpleBean.processInnerClick()}" render="innerlevel_panel"/&gt;                   
  &lt;/h:commandLink&gt;                            
  &lt;h:panelGroup id="innerlevel_panel"&gt;
  &lt;ui:repeat var="innerLevel" value="#{simpleBean.innerStrings}" 
             id="innerlevel_id"&gt;
  &lt;h:commandLink id="innerlevel_command"&gt;
  #{innerLevel} &lt;br/&gt;        
  &lt;/h:commandLink&gt;
  &lt;/ui:repeat&gt;
  &lt;/h:panelGroup&gt;
  &lt;/ui:repeat&gt;
  &lt;/h:panelGroup&gt;         
  &lt;/ui:repeat&gt;
  &lt;/h:form&gt;
  </code></pre>
  
  <p>Basically:</p>
  
  <ul>
  <li>The <code>#{simpleBean.processOuterClick()}</code> listener fires ok and the #{outerLevel} command links render</li>
  <li>But when I click on the <code>#{outerLevel}</code> command Link the <code>#{simpleBean.processInnerClick()}</code> listener is never fired</li>
  </ul>