Reputation: 2288
I am trying to create a custom tag with Facelets but it isn't rendering (i.e. the tag appears unreplaced in the response).
The tag (/WEB-INF/facelets/tags/inputThumbnailSelector.xhtml):
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:t="http://myfaces.apache.org/tomahawk">
<ui:composition>
<div style="position: relative;">
<img style="position: absolute; left: 0; top: 0;" src="#{image}"/>
<div class="thumbnail-selector" style="position: absolute; left: #{backingBean.thumbnailLeft}; top: #{backingBean.thumbnailTop};"/>
</div>
</ui:composition>
</html>
/WEB-INF/facelets/tags/panayk.taglib.xml:
<!DOCTYPE facelet-taglib PUBLIC "-//Sun Microsystems, Inc.//DTD Facelet Taglib 1.0//EN" "http://java.sun.com/dtd/facelet-taglib_1_0.dtd">
<facelet-taglib>
<namespace>http://panayk.endofinternet.org/jsf</namespace>
<tag>
<tag-name>inputThumbnailSelector</tag-name>
<source>inputThumbnailSelector.xhtml</source>
</tag>
</facelet-taglib>
My web.xml contains:
<context-param>
<param-name>javax.faces.FACELETS_LIBRARIES</param-name>
<param-value>/WEB-INF/facelets/tags/panayk.taglib.xml</param-value>
</context-param>
This is how the tag is called:
<!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:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:t="http://myfaces.apache.org/tomahawk"
xmlns:my="http://panayk.endofinternet.org/jsf">
<ui:composition template="/layout/layout.xhtml">
...
<my:inputThumbnailSelector image="${facesContext.externalContext.requestContextPath}/image/get.servlet?id=1"
backingBean="#{entryHandler}"/>
...
</ui:composition>
</html>
Many thanks in advance!
Upvotes: 4
Views: 8722
Reputation: 158
Make sure your *.taglib.xml is well configured. It happen I had the wrong namespace and it did not work. immediately as I've changed it it worked, I had auto complete (aka. code completion)
<facelet-taglib version="2.2"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facelettaglibrary_2_2.xsd">
</facelet-taglib>
Related links:
Packaging Facelets files (templates, includes, composites) in a JAR
Upvotes: 0
Reputation: 2288
I found my answer here: https://community.oracle.com/thread/1719525
I think I found the problem and the solution (which is not 100% correct). The context param should be
facelets.LIBRARIES
notjavax.faces.FACELETS_LIBRARIES
.The context param
javax.faces.FACELETS_LIBRARIES
is supposed to replace the deprecated (deprecated as per JSF specification) context paramfacelets.LIBRARIES
. When the latter is used there is a warning in the logs during server startup sayingfacelets.LIBRARIES
is deprecated andjavax.faces.FACELETS_LIBRARIES
should be used instead. But I think this is only used for logging a warning, i.e. still the namefacelets.LIBRARIES
is used to build custom taglib components. I'm saying this is not 100% correct because it should work with the new parameter name. There are other parameters which have got new names, but I didn't test them yet.
Upvotes: 7
Reputation:
I recommend doing your tags like this:
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:t="http://myfaces.apache.org/tomahawk">
<div style="position: relative;">
<img style="position: absolute; left: 0; top: 0;" src="#{image}"/>
<div class="thumbnail-selector" style="position: absolute; left: #{backingBean.thumbnailLeft}; top: #{backingBean.thumbnailTop};"/>
</div>
</ui:composition>
but everything seems ok, since you use a layout, did you wrap the custom tag in a ui:define like this ?
<ui:define name="body">
<my:inputThumbnailSelector image="${facesContext.externalContext.requestContextPath}/image/get.servlet?id=1"
backingBean="#{entryHandler}"/>
</ui:define>
Upvotes: 0