未找到 Facelets 自定义函数

发布于 2024-12-22 00:02:56 字数 1963 浏览 0 评论 0原文

我正在使用示例方法在 Facelets 中编写一个简单的自定义函数。问题是 JSF 2 应用程序无法找到该函数。错误信息是:

/test.xhtml @15,73 rendered="#{test:isGranted('ONE_ROLE')}" Function 'test:isGranted' not found.

我一直检查再检查,找不到问题所在。这里的任何评论都将非常感激,因为很明显我遗漏了一些东西(但似乎涉及的步骤非常简单)。

不知道还有没有其他要求?

提前致谢。

相关代码:

web.xml 中声明标签 XML 描述符

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

文件 test.taglib.xml

<?xml version="1.0"?>
<!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://www.test.com/security/tags</namespace>
    <function>
        <function-name>isGranted</function-name>
        <function-class>com.test.security.taglibs.IsGranted</function-class>
        <function-signature>boolean isGranted(java.lang.String role)</function-signature>
    </function>
</facelet-taglib>

标签类:

public class IsGranted extends TagHandler {
    public static boolean isGranted(String role) {
        // Do nothing. Just a test.
        return false;
    }
}

和测试文件:

<?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:test="http://www.test.com/security/tags">

    <body>
        <h:outputText value="You should NOT see this." rendered="#{test:isGranted('ONE_ROLE')}"/>     
    </body>
</html>

I'm writing a simple custom function in Facelets with a sample method. The problem is that the JSF 2 application fails to locate that function. The error message is:

/test.xhtml @15,73 rendered="#{test:isGranted('ONE_ROLE')}" Function 'test:isGranted' not found.

I've been checking and rechecking and can't find the problem. Any comment here would be really appreciated as it's clear that I'm missing something (but it seems that the steps involved are really simple).

Do you know if there are other requisites?

Thanks in advance.

The relevant code:

In the web.xml the tag XML descriptor is declared

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

The file test.taglib.xml:

<?xml version="1.0"?>
<!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://www.test.com/security/tags</namespace>
    <function>
        <function-name>isGranted</function-name>
        <function-class>com.test.security.taglibs.IsGranted</function-class>
        <function-signature>boolean isGranted(java.lang.String role)</function-signature>
    </function>
</facelet-taglib>

The tag class:

public class IsGranted extends TagHandler {
    public static boolean isGranted(String role) {
        // Do nothing. Just a test.
        return false;
    }
}

And the test file:

<?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:test="http://www.test.com/security/tags">

    <body>
        <h:outputText value="You should NOT see this." rendered="#{test:isGranted('ONE_ROLE')}"/>     
    </body>
</html>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无力看清 2024-12-29 00:02:56

在您的示例中,您声明了 sec 命名空间前缀,但在函数调用中使用了 test 前缀。但也许这只是一个复制错误。

另一个可能的原因是 taglib 文件的标头,它使用 Facelets 1.0 DTD 而不是 JSF 2.0 版本。这可能会出现问题,具体取决于您的 JSF 实现,例如对于 MyFaces,请参阅此错误报告讨论线程。 JSF 2.0 标记库的标头为:

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

In your example you are declaring the sec namespace prefix but use the test prefix in your function call. But maybe that was just a copying mistake.

Another possible cause would be the header of your taglib file, which uses the facelets 1.0 DTD instead of the JSF 2.0 version. This might be problematic depending on your JSF implementation, for example for MyFaces see this bug report and discussion thread. The header for a JSF 2.0 taglib would be:

<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">
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文