在JSF2.1上创建自定义标记库
我正在尝试创建一个自定义标记库,以便在某些项目上使用它。 当我尝试在项目中使用它时,效果很好。 如果我将WAR放在其他项目中,NetBeans会检测其名称空间和值,但当呈现页面时,它会抛出: 警告:此页调用XML命名空间 使用前缀te声明,但该命名空间不存在标记库。“ 代码基于我找到的一些博客。 以下是“taglib项目”结构:在JSF2.1上创建自定义标记库,jsf,web.xml,taglib,Jsf,Web.xml,Taglib,我正在尝试创建一个自定义标记库,以便在某些项目上使用它。 当我尝试在项目中使用它时,效果很好。 如果我将WAR放在其他项目中,NetBeans会检测其名称空间和值,但当呈现页面时,它会抛出: 警告:此页调用XML命名空间 使用前缀te声明,但该命名空间不存在标记库。“ 代码基于我找到的一些博客。 以下是“taglib项目”结构: WEB-INF |-- componentes | `-- outputText.xhtml |-- test.taglib.xhtml `-- web.
WEB-INF
|-- componentes
| `-- outputText.xhtml
|-- test.taglib.xhtml
`-- web.xml
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" 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-app_3_0.xsd">
<context-param>
<param-name>javax.faces.FACELETS_LIBRARIES</param-name>
<param-value>/WEB-INF/test.taglib.xml</param-value>
</context-param>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>index.xhtml</welcome-file>
</welcome-file-list>
</web-app>
javax.faces.FACELETS\u库
/WEB-INF/test.taglib.xml
javax.faces.PROJECT_阶段
发展
Facesservlet
javax.faces.webapp.FacesServlet
1.
Facesservlet
*.xhtml
30
index.xhtml
test.taglib.xml
<?xml version="1.0" encoding="UTF-8"?>
<!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 version="2.0" 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">
<namespace>http://test.com/test</namespace>
<tag>
<tag-name>outputText</tag-name>
<source>componentes/outputText.xhtml</source>
<attribute>
<description>Valor</description>
<name>value</name>
</attribute>
<attribute>
<description>Establece negrita</description>
<name>negrita</name>
<type>java.lang.Boolean</type>
</attribute>
</tag>
</facelet-taglib>
http://test.com/test
输出文本
组件/outputText.xhtml
英勇
价值
内格里塔庄园酒店
内格里塔
java.lang.Boolean
outputText.xhtml“hello world”示例
使用taglib(在“taglib项目”和“taglib测试仪项目”上是相同的):
普鲁士成分
有什么想法吗?该项目应该创建为一个“web片段”项目,其中包含web资源,如
.taglib.xml
文件,还包括项目的/META-INF
文件夹中的faces config.xml
CommonWebProject
|--META-INF
||--标签
|| |--foo.xhtml
|| |--bar.xhtml
| | :
| |
||--faces-config.xml
||--test.taglib.xml
||--web-fragment.xml
|`--MANIFEST.MF
:
在WAR的/WEB-INF/lib
中将这样一个项目作为JAR放置时,WAR的WEB.xml
中的整个javax.faces.FACELETS\u库
条目是不必要的
另见:
/WEB-INF/lib
中作为JAR文件结束?是的,这就是我想要的。如果在其他项目中将“模块项目”作为库导入,则它们会看到名称空间、组件及其属性,但不会呈现它们。相反,它会在web浏览器上抛出“不存在标记库”错误。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets">
<ui:composition>
<h:outputText value="#{value}" style="#{negrita ? 'font-weight: bold' : '' }"/>
</ui:composition>
</html>
<?xml version='1.0' encoding='UTF-8' ?>
<!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:te="http://test.com/test"
>
<h:head>
<title>Pruebas componentes</title>
</h:head>
<h:body>
<te:outputText value="Prueba te" negrita="true"/>
</h:body>
</html>