webtier@glassfish.java.net

How to package composite components for re-use?

From: Joel Weight <digitaljoel_at_gmail.com>
Date: Fri, 11 Dec 2009 13:46:44 -0700

I'm sorry if this is a simple question. I've spent the morning on Google
looking for a blog post or something without any luck.

Let's say I have a set of composite components in my webapp. I am now
creating a new webapp and want to use those same components in both. Rather
than copying the resources directory from one webapp to another, I would
like to have some library that I can just include in each, and then maintain
that library separately, package it in a jar, and simply include it within
each webapp project. How do I package the .xhtml files in the library so
they can be used within each webapp? I tried creating a jar with the
following structure

META-INF/resources/adc/core/echo.xhtml

then having an xmlns as follows in a page within the project

xmlns:ac="http://java.sun.com/jsf/composite/adc/core"

and referencing the tag as

        Here's the external echoer!
        <ac:echo value="Echo Me" />
        <br/>
        and here's one with the default value
        <ac:echo/>


Any help would be greatly appreciated.

Joel


For reference, here's the entire echoer 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:composite="http://java.sun.com/jsf/composite">

  <!-- INTERFACE -->
  <composite:interface>
      <composite:attribute name="value" default="Empty" />
  </composite:interface>

  <!-- IMPLEMENTATION -->
  <composite:implementation>
      Echo <h:outputText value="#{cc.attrs.value}" /> Echo
  </composite:implementation>
</html>