JSF Tip #43 - Package a composite component

If you want to share a composite component between projects you should package it in a JAR.

But how would you do it? Well it is pretty easy. First include the resources in the META-INF/resources directory. E.g.


    <?xml version='1.0' encoding='UTF-8' ?>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml"
          xmlns:h="http://java.sun.com/jsf/html"
          xmlns:cc="http://java.sun.com/jsf/composite">
        <body>
            <cc:interface></cc:interface>
            <cc:implementation>
                This is coming from a JAR-packaged composite component! Hurray :)
            </cc:implementation>
        </body>
    </html>
        

And then add a faces-config.xml in the META-INF directory. E.g.


    <?xml version='1.0' encoding='UTF-8'?>

    <faces-config version="2.1"
        xmlns="http://java.sun.com/xml/ns/javaee"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
            http://java.sun.com/xml/ns/javaee/web-facesconfig_2_1.xsd">
    </faces-config>
        

And then JAR it all up.

Posted November 20, 2013

Up