JSF Tip #49 - A nested composite component

Ever wondered how you would use a composite component within a composite component? Or is it not possible? It most certainly is possible, so lets see how!

First we define level 2 (the deepest nesting)


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

    <!DOCTYPE html>

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

Then we define level 1 (as you normally would, but now you will use a composite component within this composite component)


    <!DOCTYPE html>

    <html xmlns="http://www.w3.org/1999/xhtml"
          xmlns:cc="http://java.sun.com/jsf/composite"
          xmlns:mypanel="http://java.sun.com/jsf/composite/mypanel">
        <head>
            <title></title>
        </head>
        <body>
            <cc:interface></cc:interface>
            <cc:implementation>
                <mypanel:mypanel/>
            </cc:implementation>
        </body>
    </html>
        

And then the page where we use the nested composite component


    <!DOCTYPE html>

    <html xmlns="http://www.w3.org/1999/xhtml"
          xmlns:h="http://java.sun.com/jsf/html"
          xmlns:mypanel="http://java.sun.com/jsf/composite/mypanel">
        <h:head>
            <title>Composite component</title>
        </h:head>
        <h:body>
            <h2>Composite component</h2>
            <mypanel:nested/>
        </h:body>
    </html>
        

Posted December 2, 2013

Up