title: Partial Page Rendering using Primefaces - update is fired too early when using <ui:include>?
body: <p>I have a Webapp using Primefaces 3.3.1 (runnning on Glassfish 3.0.1) in which the user can choose the desired content in a menu. Since only a part of the page is to be refreshed, I want to use partial page refreshing with AJAX. The method to store the URL is provided in the actionListener-attribute of the commandButton, whereas the id of the component which must be updated is provided in the update-attribute of the commandButton.</p>
  
  <p>I'll attach my sample sourcecode first - which I got from another thread regarding PPR, but was confirmed to be working:</p>
  
  <p><strong>main.xhtml</strong></p>
  
  <pre><code>&lt;html xmlns="http://www.w3.org/1999/xhtml"
        xmlns:h="http://java.sun.com/jsf/html"
        xmlns:p="http://primefaces.org/ui"
        xmlns:ui="http://java.sun.com/jsf/facelets"&gt;
  
      &lt;h:body&gt;
          &lt;h:panelGroup id="content" layout="block"&gt;
              &lt;ui:include src="#{navBean.activePage}" /&gt;
          &lt;/h:panelGroup&gt;
  
          &lt;h:form&gt;
              &lt;p:commandButton value="next"
                               actionListener="#{navBean.next}" 
                               update=":content" /&gt;
              &lt;p:commandButton value="back"
                               actionListener="#{navBean.back}" 
                               update=":content" /&gt;
          &lt;/h:form&gt;
      &lt;/h:body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>NavBean</strong></p>
  
  <pre><code>import javax.faces.bean.ManagedBean;
  import javax.faces.bean.SessionScoped;
  import javax.faces.event.ActionEvent;
  
  @ManagedBean
  @SessionScoped
  public class NavBean {
  
      private String activePage = "somepage.xhtml";
  
  
      public String getActivePage() {
          return activePage;
      }
  
  
      public void setActivePage(String activePage) {
          this.activePage = activePage;
      }
  
  
      public void next(ActionEvent e) {
          this.setActivePage("someotherpage.xhtml");
      }
  
  
      public void back(ActionEvent e) {
          this.setActivePage("somepage.xhtml");
      }
  }
  </code></pre>
  
  <p><strong>Sample included page ("somepage.xhtml")</strong></p>
  
  <pre><code>&lt;ui:composition xmlns="http://www.w3.org/1999/xhtml"
                  xmlns:ui="http://java.sun.com/jsf/facelets"&gt;
  
      &lt;h2&gt;Just some content for testing purposes&lt;/h2&gt;
  
  &lt;/ui:composition&gt;
  </code></pre>
  
  <p>Now, the problem is, that <code>getActivePage</code> is <strong>always</strong> called before <code>setActivePage</code> - which is obviously a problem because one would have to click a button twice for getting the new content. </p>
  
  <p>I have a feeling that I am missing something essential here, buts earching on Google/stackoverflow did not bring any applicable results.</p>
  
  <p><strong>Update</strong>: Replacing <code>actionListener</code> with <code>action</code> did not work (I of course changed the input parameters of the called methods accordingly).</p>
  
  <p>As erencan suggested in his comment below, I replaced the <code>&lt;ui:include&gt;</code> with a <code>&lt;h:outputText&gt;</code>for displaying only a string:</p>
  
  <pre><code>&lt;h:outputText value="#{navBean.activePage}" /&gt;
  </code></pre>
  
  <p>Contrary of my expectations, this is working fine. So why does <code>&lt;h:outputText&gt;</code> work, whereas <code>&lt;ui:include&gt;</code> does not? Using the former is not an option, since I want to use JSFs templating features.</p>