我正在尝试使用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="www.w3/1999/xhtml" xmlns:f="java.sun/jsf/core" xmlns:h="java.sun/jsf/html" xmlns:ui="java.sun/jsf/facelets" xmlns:t="myfaces.apache/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" "java.sun/dtd/facelet-taglib_1_0.dtd"> <facelet-taglib> <namespace>panayk.endofinternet/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" "www.w3/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="www.w3/1999/xhtml" xmlns:f="java.sun/jsf/core" xmlns:h="java.sun/jsf/html" xmlns:ui="java.sun/jsf/facelets" xmlns:t="myfaces.apache/tomahawk" xmlns:my="panayk.endofinternet/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/thread/1719525
I found my answer here: community.oracle/thread/1719525
我认为我找到了问题和解决方案(并非100%正确). 上下文参数应该为facelets.LIBRARIES而不是javax.faces.FACELETS_LIBRARIES .
I think I found the problem and the solution (which is not 100% correct). The context param should be facelets.LIBRARIES not javax.faces.FACELETS_LIBRARIES.
上下文参数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自定义标签未呈现
发布评论