未找到Facelets自定义功能 [英] Facelets custom function not found

查看:88
本文介绍了未找到Facelets自定义功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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?

谢谢.

相关代码:

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

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> 

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

推荐答案

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

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.

另一个可能的原因是您的taglib文件的标头,该标头使用facelets 1.0 DTD而不是JSF 2.0版本.根据您的JSF实现,这可能会出现问题,例如,有关MyFaces的信息,请参见此错误报告讨论线程. JSF 2.0 taglib的标头为:

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

这篇关于未找到Facelets自定义功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆