Skip to main content

JSF Tip #37 - Create a composite component

Posted by mriem on November 12, 2013 at 2:43 PM PST

Creating and using a composite component is very straightforward.

1. Creating the composite component
2. Using the composite component

Creating the composite component

<?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 composite component! Hurray :)
        </cc:implementation>
    </body>
</html>

Using the 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:mypanel/>
    </h:body>
</html>

Note the code for this sample is available as part of the Glassfish samples (see the subversion repository at http://svn.java.net/svn/glassfish-samples~svn/trunk/ws/javaee7)

And that is it.

Enjoy!

Related Topics >>