Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I understand that your question basically boils down to <em>How can I include Facelets views in a JAR?</em></p> <p>You can do this by placing a custom <a href="http://download.oracle.com/javaee/6/api/javax/faces/view/facelets/ResourceResolver.html" rel="nofollow noreferrer"><code>ResourceResolver</code></a> in the JAR.</p> <pre class="lang-java prettyprint-override"><code>public class FaceletsResourceResolver extends ResourceResolver { private ResourceResolver parent; private String basePath; public FaceletsResourceResolver(ResourceResolver parent) { this.parent = parent; this.basePath = "/META-INF/resources"; // TODO: Make configureable? } @Override public URL resolveUrl(String path) { URL url = parent.resolveUrl(path); // Resolves from WAR. if (url == null) { url = getClass().getResource(basePath + path); // Resolves from JAR. } return url; } } </code></pre> <p>Configure this in webapp's <code>web.xml</code> as follows:</p> <pre class="lang-xml prettyprint-override"><code>&lt;context-param&gt; &lt;param-name&gt;javax.faces.FACELETS_RESOURCE_RESOLVER&lt;/param-name&gt; &lt;param-value&gt;com.example.FaceletsResourceResolver&lt;/param-value&gt; &lt;/context-param&gt; </code></pre> <p>Imagine that you've a <code>/META-INF/resources/foo/bar.xhtml</code> in <code>random.jar</code>, then you can just include it the usual way</p> <pre class="lang-xml prettyprint-override"><code>&lt;ui:include src="/foo/bar.xhtml" /&gt; </code></pre> <p>or even dynamically</p> <pre class="lang-xml prettyprint-override"><code>&lt;ui:include src="#{bean.path}" /&gt; </code></pre> <p>Note: since Servlet 3.0 and newer JBoss/JSF 2.0 versions, the whole <code>ResourceResolver</code> approach is not necessary if you keep the files in <code>/META-INF/resources</code> folder. The above <code>ResourceResolver</code> is only mandatory in Servlet 2.5 or older JBoss/JSF versions because they've bugs in <code>META-INF</code> resource resolving.</p> <h3>See also:</h3> <ul> <li><a href="https://stackoverflow.com/questions/3531432/packaging-facelets-pages-in-a-jar">Packaging Facelets files (templates, includes, composites) in a JAR</a></li> <li><a href="https://stackoverflow.com/questions/9290482/jsf-facelets-template-packaging">JSF facelets template packaging</a></li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload