Facelets自定义标记无法呈现

时间:2010-06-25 13:22:19

标签: jsf facelets

我正在尝试使用Facelets创建自定义标记,但它不会呈现(即标记在响应中显示为未替换)。

标签(/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>

我的web.xml包含:

<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>

非常感谢提前!

3 个答案:

答案 0 :(得分:7)

我在这里找到了答案:https://community.oracle.com/thread/1719525

  

我认为我发现了问题和解决方案(不是100%正确)。 上下文参数应为facelets.LIBRARIES而不是javax.faces.FACELETS_LIBRARIES

     

上下文参数javax.faces.FACELETS_LIBRARIES应该替换已弃用的(根据JSF规范弃用)上下文参数facelets.LIBRARIES。使用后者时,服务器启动期间日志中会显示警告,说明{@ 1}}已弃用,而应使用facelets.LIBRARIES。但我认为这仅用于记录警告,即仍然使用名称javax.faces.FACELETS_LIBRARIES来构建自定义taglib组件。我说这不是100%正确,因为它应该与新的参数名称一起使用。还有其他参数有新名称,但我还没有测试它们。

答案 1 :(得分:0)

我建议你做这样的标签:

<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>

但是一切似乎都没问题,因为你使用了一个布局,你是否将自定义标签包装在一个ui中:这样定义?

<ui:define name="body">
<my:inputThumbnailSelector image="${facesContext.externalContext.requestContextPath}/image/get.servlet?id=1" 
            backingBean="#{entryHandler}"/>
</ui:define>

答案 2 :(得分:0)

确保您的* .taglib.xml配置正确。碰巧我有错误的命名空间,它没有用。 我立刻改变了它的工作原理,我自动完成了(又称代码完成)

<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>

相关链接:

JSF 2.2: New namespaces

Packaging Facelets files (templates, includes, composites) in a JAR

相关问题