在.tld文件中声明的自定义JSF组件在JSP中工作,但在Facelets中不工作

在.tld文件中声明的自定义JSF组件在JSP中工作,但在Facelets中不工作,jsp,jsf,migration,facelets,taglib,Jsp,Jsf,Migration,Facelets,Taglib,我有一个自定义JSF组件,它注册在.tld文件中。当我声明如下时,它在JSP中运行良好: <%@taglib uri="http://example.com/ui" prefix="ex"%> <html xmlns:ex="http://example.com/ui"> <facelet-taglib xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/

我有一个自定义JSF组件,它注册在
.tld
文件中。当我声明如下时,它在JSP中运行良好:

<%@taglib uri="http://example.com/ui" prefix="ex"%>
<html xmlns:ex="http://example.com/ui">
<facelet-taglib
    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"
    version="2.2">

但是,当我尝试声明如下时,它在Facelets中不起作用:

<%@taglib uri="http://example.com/ui" prefix="ex"%>
<html xmlns:ex="http://example.com/ui">
<facelet-taglib
    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"
    version="2.2">


如何在Facelets中也使用自定义JSF组件?

JSP和Facelets是完全不同的视图技术。JSP是基于Servlet的,而Facelets是基于XML的。不能在另一个上重复使用其中一个的标记/标记库。JSP的
*.tld
文件是facelet的
*.taglib.xml
文件

以下是JSF 2.0中Facelets taglib文件的启动示例:

<?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/ui</namespace>

    <tag>
        <tag-name>foo</tag-name>
        <component>
            <component-type>com.example.Foo</component-type>
        </component>
    </tag>
</facelet-taglib>
如果您决定选择JSF 2.2作为最低要求,请更新taglib的根声明,如下所示:

<%@taglib uri="http://example.com/ui" prefix="ex"%>
<html xmlns:ex="http://example.com/ui">
<facelet-taglib
    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"
    version="2.2">

另见:

应该注意的是,JSP自2009年以来就被弃用为JSF的视图技术。因此,如果您打算构建一个新的自定义组件库,那么让它与JSP兼容将是一种完全的浪费,因为没有一个头脑清醒的JSF开发人员会使用它。此外,几乎所有JSF2.x组件库都不再支持JSP。

JSP和Facelets是完全不同的视图技术。JSP是基于Servlet的,而Facelets是基于XML的。不能在另一个上重复使用其中一个的标记/标记库。JSP的
*.tld
文件是facelet的
*.taglib.xml
文件

以下是JSF 2.0中Facelets taglib文件的启动示例:

<?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/ui</namespace>

    <tag>
        <tag-name>foo</tag-name>
        <component>
            <component-type>com.example.Foo</component-type>
        </component>
    </tag>
</facelet-taglib>
如果您决定选择JSF 2.2作为最低要求,请更新taglib的根声明,如下所示:

<%@taglib uri="http://example.com/ui" prefix="ex"%>
<html xmlns:ex="http://example.com/ui">
<facelet-taglib
    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"
    version="2.2">

另见:
应该注意的是,JSP自2009年以来就被弃用为JSF的视图技术。因此,如果您打算构建一个新的自定义组件库,那么让它与JSP兼容将是一种完全的浪费,因为没有一个头脑清醒的JSF开发人员会使用它。此外,实际上所有JSF2.x组件库都不再支持JSP