title: Including a Facelet with FaceletContext#includeFacelet() doesn't work in JSF 2.0
body: <p>I'm trying to inject a Facelet into a portion my main page programmatically using <code>FaceletContext#includeFacelet()</code> (I can't use a <code>&lt;ui:include&gt;</code>) and after reading the answer to <a href="https://stackoverflow.com/questions/10853177/how-to-use-the-includehandler-inside-my-custom-component">this question</a>, I wrote the following code (it's a simple test case): </p>
  
  <p>The view, <code>index.xhtml</code>:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="ISO-8859-1" ?&gt;
  &lt;!DOCTYPE html&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:c="http://java.sun.com/jsp/jstl/core"&gt;
      &lt;h:head&gt;
          &lt;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /&gt;
          &lt;title&gt;Insert title here&lt;/title&gt;
          &lt;script src="JS/jquery-1.8.3.js" /&gt;
          &lt;script type="text/javascript"&gt;
              $(function(){
                  $('#mondiv').click(function(){
                      console.log("mondiv is clicked !");                     
                      includefacelet();
                  });
              });
          &lt;/script&gt;
      &lt;/h:head&gt;
      &lt;body&gt;
          &lt;h:form id="form1"&gt;
              &lt;div id="mondiv" style="background-color: red; position: absolute; width: 20px; height: 20px;" /&gt;
              &lt;p:remoteCommand name="includefacelet" actionListener="#{bean.includefacelet}" /&gt;
              &lt;br /&gt;&lt;br /&gt;
              &lt;h:panelGroup id="pg" layout="block" style="background-   color:blue;position:absolute;width:200px;height:200px;" /&gt;
          &lt;/h:form&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>The managed bean:</p>
  
  <pre><code>package beans.a4jTests;
  
  import java.io.IOException;
  
  import javax.faces.application.Application;
  import javax.faces.bean.ManagedBean;
  import javax.faces.bean.SessionScoped;
  import javax.faces.component.UIComponent;
  import javax.faces.component.UIForm;
  import javax.faces.component.html.HtmlPanelGroup;
  import javax.faces.context.FacesContext;
  import javax.faces.view.facelets.FaceletContext;
  
  import org.primefaces.context.RequestContext;
  
  @ManagedBean
  @SessionScoped
  public class Bean {
  
      public void includefacelet(){
          FacesContext fc = FacesContext.getCurrentInstance();
          UIForm form1 = (UIForm) fc.getViewRoot().findComponent("form1");
          HtmlPanelGroup pg = (HtmlPanelGroup) form1.findComponent("pg");
          FaceletContext faceletContext = (FaceletContext) fc.getAttributes().get(FaceletContext.FACELET_CONTEXT_KEY);
  
          try {
              faceletContext.includeFacelet(pg, "NewFile.html");
          } catch (IOException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
  
          //Refrsh
          RequestContext context = RequestContext.getCurrentInstance();         
          context.update("form1");
          context.update("pg");
          System.out.println("includefacelet is executed");
      }
  
  }
  </code></pre>
  
  <p>The include, <code>newfile.html</code>:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="ISO-8859-1" ?&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
      &lt;head&gt;
          &lt;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /&gt;
          &lt;title&gt;Insert title here&lt;/title&gt;
      &lt;/head&gt;
      &lt;body&gt;
          Hello ! this is the newfile.html
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>I don't know why, not only nothing happens even the bean method was executed but also the bean method seems stopping to be executed for a second click and I didn't get any exception during the whole execution.</p>