I think, therefore I blog

JSF Composite Components Where You Want Them

By , 6 July 2012

JSF Composite Components Where You Want Them
JSF Composite Components Where You Want Them

As Ryan Lubke commented in the Facelets Tags vs Composite Components thread, JSF composite components must be kept in the /resources directory in your webapp. This grates against my "package-by-feature" style of programming. I want all my related code together thanks.

Fortunately there are two ways to work around this problem.

  1. Symlinks. Standard Unix symlinks from the resources directory work fine for me. Symlinks tend to be a bit flaky though, so you might prefer to try...
  2. Decoration. Facelets knows no bounds when it comes to organising your templates. You can use normal Facelets decoration to redirect your xhtml templates under the resources directory to the real implementation:
    <ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
JSF Composite Components Where You Want Them

That's not perfect, but it lets me keep all my related code together. To make things a little neater, you can actually use the same namespace for composite components and regular components. Just declare the location of your composite resources directory in the taglib.xml like this:


I don't see any reason why composite components should not be able to be added to taglib.xml. If I had it my way, the existing Facelets <tag> feature would just look in the tag file for <cc:implementation> and handle it as a composite component if one is found.

In fact, composite components and tag files should be the same thing.


About Roger Keays

JSF Composite Components Where You Want Them

Roger Keays is an artist, an engineer, and a student of life. Since he left Australia in 2009, he has been living as a digital nomad in over 40 different countries around the world. Roger is addicted to surfing. His other interests are music, psychology, languages, and finding good food. Click here to subscribe to his weekly blog, or stalk him on Facebook and Twitter.

Leave a Comment

Please visit https://RogerKeays.com/jsf-2-0-composite-components-where-you-want-them to add your comments.

Comment posted by: Dimitris Kalogirou, 4 years ago

Hello Roger,

Great blog.

Is there any email to contact you in private?



Join Over 1000 Subscribers

I write every Sunday about travel, psychology, and technology. Thousands of people just like you have already subscribed—and for good reason. It'll change your life. And it's free :)

Read a Good Book

“A spellbinding true story of love, passion and adventure. One can’t help but be swept away by 100% Love Guaranteed.” —Dr Tammie Matson, author of Elephant Dance.

Chat For A While

Your Vote Matters

Which animal will take over when humans go extinct?