Question

I am trying to create a facelets taglib. Every tutorial I read so far tells to place the *.taglib.xml file and the tag files themselves inside the WEB-INF directory, but none actually says why. If I try to move the tag files to another directory and update the *.taglib.xml to point to the moved files I get the following TagException:

/confirmation/fields/ordersearchalternatives.xhtml @33,42 <s:orderSearchAlternatives> null

javax.faces.view.facelets.TagException: /confirmation/fields/ordersearchalternatives.xhtml @33,42 <s:orderSearchAlternatives> null
  at com.sun.faces.facelets.tag.UserTagHandler.apply(UserTagHandler.java:144)
  at javax.faces.view.facelets.DelegatingMetaTagHandler.applyNextHandler(DelegatingMetaTagHandler.java:137)
  at com.sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.apply(ComponentTagHandlerDelegateImpl.java:203)

The same happens if the *.taglib.xml file is moved to another directory and the web.xml points to that.

It only seems to work if the tags' XHTML files and the taglib descriptor are inside the WEB-INF directory. What I would like to achieve is to have the taglib descriptor as well as the tags' XHTML files inside e.g. the resources directory and have the web.xml file pointing to it.

  • Is that possible?
  • Is that completely out of best practice?
Was it helpful?

Solution

Maybe this helps someone else: Stumbling over this SO post I figured out how to host my taglibs outside the WEB-INF directory. The javax.faces.FACELETS_LIBRARIES context param in web.xml tells JSF to look for one or more specific .taglib.xml file(s) in the given locations. The directories are all relative to the web directory.

<context-param>
  <param-name>javax.faces.FACELETS_LIBRARIES</param-name>
  <param-value>/shared/taglibs/y.taglib.xml;/other/taglibs/x.taglib.xml</param-value>
</context-param>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top