title: Programmatically include xhtml fragment in MyFaces
body: <p>I know it is possible in MyFaces to programmatically add a xhtml fragment to the component tree, instead of using <code>ui:include</code>.</p>
  
  <p>The snipplet I am talking about is as (in the original form):</p>
  
  <pre><code>ViewDeclarationLanguage vdl = facesContext.getApplication().getViewHandler().getViewDeclarationLanguage(facesContext, facesContext.getViewRoot().getViewId());
  
  Map&lt;String, Object&gt; attributes = new HashMap&lt;String, Object&gt;();
  attributes.put("src", "/fragmentToInclude.xhtml");
  UIComponent component = vdl.createComponent(facesContext, "http://java.sun.com/jsf/facelets", "include", attributes);
  </code></pre>
  
  <p><br/></p>
  
  <p><strong>The problem</strong> I am facing is I am <strong>not able to pass in parameters</strong>, that would normally be passed in via <code>&lt;ui:param .../&gt;</code> tag.</p>
  
  <p>What I tried, of course, was to add params into <code>attributes</code> map:</p>
  
  <pre><code>attributes.put("testingParam1", "Yeah, it worked!");
  </code></pre>
  
  <p>But this seems not to help. Content of my testing fragment is quite simple:</p>
  
  <pre><code> &lt;ui:composition xmlns:ui="http://xmlns.jcp.org/jsf/facelets"&gt;
       &lt;div class="testingDiv"&gt;#{empty testingParam1 ? 'testingParam1 IS EMPTY' : testingParam1}&lt;/div&gt;
   &lt;/ui:composition&gt;
  </code></pre>
  
  <p>The fragment is properly loaded, but I only get that 'is empty' message.</p>
  
  <p>I have walked through multiple resources but haven't found answer there:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/24145294/nullpointerexception-in-myfaces-facelet-inclusion">NullPointerException in MyFaces facelet inclusion</a></li>
  <li><a href="http://lu4242.blogspot.cz/2014/01/whats-new-in-myfaces-22.html" rel="nofollow noreferrer">http://lu4242.blogspot.cz/2014/01/whats-new-in-myfaces-22.html</a></li>
  <li><a href="https://java.net/projects/javaserverfaces-spec-public/lists/jsr344-experts/archive/2014-03/message/12" rel="nofollow noreferrer">https://java.net/projects/javaserverfaces-spec-public/lists/jsr344-experts/archive/2014-03/message/12</a></li>
  <li><a href="https://java.net/projects/javaserverfaces-spec-public/lists/users/archive/2014-10/message/120" rel="nofollow noreferrer">https://java.net/projects/javaserverfaces-spec-public/lists/users/archive/2014-10/message/120</a></li>
  </ul>
  
  <p>Please, do you know, is this even possible? Or am I missing something? Thanks for any hints.</p>