问题描述
我正在尝试使用Facelets创建一个自定义标签,但该标签无法呈现(即该标签在响应中显示为未替换).
I am trying to create a custom tag with Facelets but it isn't rendering (i.e. the tag appears unreplaced in the response).
标记(/WEB-INF/facelets/tags/inputThumbnailSelector.xhtml):
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:
/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>
我的web.xml包含:
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>
这是标签的调用方式:
<!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>
非常感谢!
推荐答案
我在这里找到了答案: https ://community.oracle.com/thread/1719525
I found my answer here: https://community.oracle.com/thread/1719525
上下文参数javax.faces.FACELETS_LIBRARIES
应该替换不推荐使用(根据JSF规范不推荐使用)的上下文参数facelets.LIBRARIES
.如果使用后者,则在服务器启动期间日志中会显示一条警告,提示已弃用facelets.LIBRARIES
,而应改用javax.faces.FACELETS_LIBRARIES
.但是我认为这仅用于记录警告,即名称facelets.LIBRARIES
仍用于构建自定义taglib组件.我说这不是100%正确,因为它应该与新的参数名称一起使用.还有其他一些具有新名称的参数,但我尚未对其进行测试.
The context param javax.faces.FACELETS_LIBRARIES
is supposed to replace the deprecated (deprecated as per JSF specification) context param facelets.LIBRARIES
. When the latter is used there is a warning in the logs during server startup saying facelets.LIBRARIES
is deprecated and javax.faces.FACELETS_LIBRARIES
should be used instead. But I think this is only used for logging a warning, i.e. still the name facelets.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.
这篇关于Facelets自定义标签未呈现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!