Allow multiple taglib.xml files for the same namespace

From: Matthias Berndt <>
Date: Fri, 13 Nov 2009 16:01:35 +0100


first I'd like to explain my intention. The scenario is writing multiple
JSF components being bundled in more than one java archive. Each java
archive has its own taglib.xml descriptor so you can use them
separately. These components belong to the same project or organisation
and should be published within the same namespace. This isn't possible
with facelets at the moment and is a known issue to facelets. See:

To support this scenario I'm aware of 3 possible solutions.

The first one is merging the needed java archives especially the
taglib.xml. I think this one is bad because the separation between the
component projects is destroyed.

The second one is merging the taglib definitions while being processed
by FaceletTaglibConfigProcessor#processTagLibrary(). In line 308 a new
TagLibraryImpl is created for every facelet-taglib element. This can be
extended to use an already existing TagLibraryImpl for a specific
namespace. This extension requires about 10 to 15 lines of code. As a
result there will be one TagLibraryImpl for multiple facelet-taglib
elements with the same namespace.

The third one, my preferd one, is using the existing
CompositeTagLibrary. As a result and in contrast to the second method
each facelet-taglib element will be represented by a TagLibraryImpl and
combined by CompositeTagLibrary. This requires only a minor change. In
FaceletTaglibConfigProcessor#processTagLibrary() in line 318 the created
TagLibraryImpl is added to the compiler. Compiler#addTagLibrary() tests
if the given library is already known to the compiler. Subsequently this
is done by using equals() and hashCode() in AbstractTagLibrary. At the
moment hashCode() is implemented to use nothing except the namespace. If
there are multiple TagLibraryImpl with the same namespace only one will
be included in the compiler. The rest is thrown away. By extending
hashCode() to use this.factories and this.functions in the calculation
multiple TagLibraryImpl with different tags etc. can coexist. IMO it
makes sense by reason taglibs are not equal only because they define the
same namespace.
CompositeTagLibrary handles this very well so no other changes are

I attached a patch to modify AbstractTagLibrary#hashCode(). The
algorithm is base on Joshua Bloch's Effective Java. The existing test
cases are not harmed and apologize my self not writing a specific test
case. I don't like to call it a patch because it's so stupidly simple,
but I'd be glad if something like it could be shipped with JSF2 to
provide this feature.

kind regards,
Matthias Berndt