2013-06-06 41 views
0

我有下:如何通過定製Facelet標記ATTR實施在JSF 2

/src/main/webapp/WEB-INF/web.xml

<?xml version="1.0" encoding="utf-8"?> 

<webapp> 
    <context-param> 
     <param-name>javax.faces.FACELETS_LIBRARIES</param-name> 
     <param-value>/WEB-INF/my-taglib.xml</param-value> 
    </context-param> 
</webapp> 

/src目錄/main/webapp/WEB-INF/my-tablib.xml

<?xml version="1.0" encoding="UTF-8"?> 

<facelet-taglib xmlns="http://java.sun.com/xml/ns/javaee" 
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
       xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facelettaglibrary_2_0.xsd" 
       version="2.0"> 
    <namespace>http://example.com/jsf/taglib</namespace> 
    <tag> 
     <tag-name>my-tag</tag-name> 
     <!-- /src/main/webapp/WEB-INF/tags/com/example/myTag.xml --> 
     <source>tags/com/example/myTag.xml</source> 
    </tag> 
</facelet-taglib> 

/src/main/webapp/WEB-INF/tags/com/example/myTag.xml

<!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:h="http://java.sun.com/jsf/html" 
     xmlns:composite="http://java.sun.com/jsf/composite"> 

    <composite:interface> 
     <composite:attribute name="customAttr" /> 
    </composite:interface> 

    <composite:implementation> 
     <h:outputText value="#{cc.attrs.customAttr}" /> 
    </composite:implementation> 
</html> 

/src/main/webapp/index.xhtml

<html xmlns="http://www.w3.org/1999/xhtml" 
     xmlns:h="http://java.sun.com/jsf/html" 
     xmlns:ui="http://java.sun.com/jsf/facelets" 
     xmlns:exui="http://example.com/jsf/taglib"> 
    <h:head> 
    </h:head> 
    <h:body> 
     <exui:my-tag customAttr="showMe" /> 
    </h:body> 
</html> 

結果,我沒有看到 「SHOWME」 信息戰部署後。如何解決這個問題?

回答

0

你把複合材料部件的/resources/<composite name>文件夾(無需添加my-tablib.xmlweb.xml), 例如:

enter image description here

,然後就可以通過申報使用:

<html xmlns="http://www.w3.org/1999/xhtml" 
      ... 
      xmlns:cps="http://java.sun.com/jsf/composite/composites/CPSI35" 
      > 
      ... 
      <cps:cpscontact ....></cps:cpscontact>