Cjxcz Odjcayrwl
Cjxcz Odjcayrwl

Reputation: 22847

Is it necessary to declare tags in facelet taglib 2.0?

I've read the tutorial: http://jsflive.wordpress.com/2011/03/24/custom-component-library/ in which the authors are making empty .taglib.xml file, and according to tutorial the tags should be automatically loaded from the resource subfolder.

However, by me I have exception:

javax.faces.FacesException: Could not get component metadata for myComponent.xhtml

I have to manually specify each tag:

<tag>
    <tag-name>myComponent</tag-name>
    <source>tags/mylib/myComponent.xhtml</source>
</tag>

Am I missing something? Where the tag definition locations would be automatically resolved? I'm running on WebSphere 7.0 and MyFaces 2.0.7.

Upvotes: 2

Views: 4815

Answers (1)

Michi
Michi

Reputation: 1595

I think you mix things up here. In my above mentioned blog post I added composite components to the tag lib like this:

<facelet-taglib>
  <namespace>http://jsflive.at/taglib</namespace>
  <composite-library-name>jsflive</composite-library-name>
</facelet-taglib>

This adds all composite components of the resource library with the name specified in composite-library-name. The tag names are derived from the file names by convention.

You on the contrary specify a tag for a Facelets fragment:

<tag>
  <tag-name>myComponent</tag-name>
  <source>tags/mylib/myComponent.xhtml</source>
</tag>

This has nothing to do with composite components! This approach is the pre JSF 2.0 way of defining custom tags for Facelets fragments. Your code creates a tag for the referenced xhtml file, which could be an arbitrary Facelets file. The path is relative to the location of the taglib.xml file in this case.

JSF 2.2 however will provide a way to specify tags for specific composite components. My post http://jsflive.wordpress.com/2013/04/06/jsf22-cc-taglib/ shows how this works.

Upvotes: 2

Related Questions