title: FaceletContext is Null
body: <p>I have a JSF 2.0 project that I am unable to obtain a FaceletContext from. </p>
  
  <p>Here is the setup from my web.xml:</p>
  
  <pre><code>&lt;servlet&gt;
      &lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt;
      &lt;servlet-class&gt;javax.faces.webapp.FacesServlet&lt;/servlet-class&gt;
      &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
  &lt;/servlet&gt;
  &lt;context-param&gt;
      &lt;param-name&gt;javax.faces.PROJECT_STAGE&lt;/param-name&gt;
      &lt;param-value&gt;Development&lt;/param-value&gt;
  &lt;/context-param&gt;
  
  &lt;context-param&gt;
      &lt;param-name&gt;facelets.DEVELOPMENT&lt;/param-name&gt;
      &lt;param-value&gt;true&lt;/param-value&gt;
  &lt;/context-param&gt;
  
  &lt;context-param&gt;
      &lt;param-name&gt;javax.faces.STATE_SAVING_METHOD&lt;/param-name&gt;
      &lt;param-value&gt;server&lt;/param-value&gt;
  &lt;/context-param&gt;
  
  &lt;context-param&gt;
      &lt;param-name&gt;javax.faces.PARTIAL_STATE_SAVING&lt;/param-name&gt;
      &lt;param-value&gt;false&lt;/param-value&gt;
  &lt;/context-param&gt;
  
  &lt;context-param&gt;
      &lt;param-name&gt;javax.faces.FULL_STATE_SAVING_VIEW_IDS&lt;/param-name&gt;
      &lt;param-value&gt;/index.xhtml&lt;/param-value&gt;
  &lt;/context-param&gt;
  &lt;context-param&gt;
      &lt;param-name&gt;javax.faces.DEFAULT_SUFFIX&lt;/param-name&gt;
      &lt;param-value&gt;.xhtml&lt;/param-value&gt;
  &lt;/context-param&gt;
  
  &lt;context-param&gt;
      &lt;param-name&gt;javax.faces.application.CONFIG_FILES&lt;/param-name&gt;
      &lt;param-value&gt;/WEB-INF/faces-config.xml&lt;/param-value&gt;
  &lt;/context-param&gt;
  
  &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/faces/*&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  </code></pre>
  
  <p>I can obtain the FacesContext, but not the FaceletContext. The following lines of code are where the issue lies:</p>
  
  <pre><code>            FacesContext fctx = FacesContext.getCurrentInstance(); //works
      //FaceletContext f2ctx = (FaceletContext) fctx.getAttributes().get(FaceletContext.FACELET_CONTEXT_KEY);
      FaceletContext f2ctx = (FaceletContext) fctx.getELContext().getContext(FaceletContext.class);
  </code></pre>
  
  <p>Can anyone assist?</p>
  
  <p>Update:</p>
  
  <p>The above was a snippet from my overall goal: loading a facelet file containing a dialog on demand, then add it to a parent to display. The code below is incomplete, but should explain what I'm getting at. Note that the app uses the Primefaces library, hence the RequestContext object.</p>
  
  <pre><code>public void launch() {
  
      form.getChildren().clear();
  
      FacesContext fctx = FacesContext.getCurrentInstance();
      for (Object o: fctx.getAttributes().keySet()) {
          System.out.println(o.toString());
      }
  
      FaceletContext f2ctx = (FaceletContext) fctx.getAttributes().get(FaceletContext.FACELET_CONTEXT_KEY);
      //FaceletContext f2ctx = (FaceletContext) fctx.getELContext().getContext(FaceletContext.class);
      dialog = new Dialog();
  
      try {
          f2ctx.includeFacelet(dialog, "/WEB-INF/facelets/dialog/manager.xhtml");
          form.getChildren().add(dialog);
      } catch (IOException ex) {
          log.debug(ex.toString());
      }
  
      RequestContext.getCurrentInstance().update("mainPageCenterForm");
  }
  </code></pre>