JSF 配置注释未处理

发布于 2024-11-15 20:22:35 字数 762 浏览 3 评论 0原文

我正在 JBoss AS 6 上运行 JSF 2 应用程序

。不知何故,容器不会处理注释,例如 @FacesComponent 或 @FacesValidator 等。如果我用 @FacesValidator("fooValidator") 注释 Bean 并尝试将某些组件上的 validatorId 设置为 "fooValidator" 我得到:

Caused by: javax.faces.FacesException: Expression Error: Named Object: fooValidator not found.
at com.sun.faces.application.ApplicationImpl.createValidator(ApplicationImpl.java:1530) [:2.0.3-]
...

但是,如果我添加

    <validator>
      <validator-id>fooValidator</validator-id>
      <validator-class>foo.MyClass</validator-class>
    </validator>

到我的faces-config.xml,一切都会按预期工作。组件和转换器也是如此。

知道为什么注释没有被处理吗?我没有主意...

提前谢谢...

I am running a JSF 2 application on JBoss AS 6.

Somehow the Annotations, like @FacesComponent or @FacesValidator, etc are not processed by the container. If I annotate a Bean with @FacesValidator("fooValidator") and try to set the validatorId on some component to "fooValidator" I get:

Caused by: javax.faces.FacesException: Expression Error: Named Object: fooValidator not found.
at com.sun.faces.application.ApplicationImpl.createValidator(ApplicationImpl.java:1530) [:2.0.3-]
...

However, If I add

    <validator>
      <validator-id>fooValidator</validator-id>
      <validator-class>foo.MyClass</validator-class>
    </validator>

To my faces-config.xml everything works as expected. Same goes for components and converters.

Any idea why the annotations are not processed? I am out of ideas...

Thanks in advance...

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

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

发布评论

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

评论(2

白色秋天 2024-11-22 20:22:35

知道了。它与此非常相似: 为什么不“JSF 2.0 RI (Mojarra) 扫描我的类”注释吗?

我的项目使用 skinny war,所以war中的lib文件夹为空/不存在。更糟糕的是,控制器豆并不位于战争中,而是位于一个单独的罐子中。由于此 jar 不在 war 中,因此 jsf 注释处理器不会扫描它。

我想,我会重组这个项目,并可能放弃这场瘦身战争。那应该解决它。

Got it. It is very similar to this one: Why doesn't JSF 2.0 RI (Mojarra) scan my class' annotations?

My project uses a skinny war, so the lib folder in the war is empty/nonexistent. And to make it worse, the Controller Beans are not located in the war but in a seperate jar. As this jar is not in the war, the jsf annotation processor does not scan it.

I guess, I will restructure the project and likely throw out the skinny war. That should fix it.

青衫负雪 2024-11-22 20:22:35

那么,您在托管 bean 上使用的是 @Named 而不是 @ManagedBean 吗? :)

如果 faces-config.xml 未声明为符合 JSF 2.0 规范,则可能会发生这种情况。确保根声明如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<faces-config
    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-facesconfig_2_0.xsd"
    version="2.0">

    <!-- config here -->

</faces-config>

So, you were using @Named instead of @ManagedBean on your managed beans? :)

This can happen if the faces-config.xml is not declared conform JSF 2.0 spec. Ensure that the root declaration look like this:

<?xml version="1.0" encoding="UTF-8"?>
<faces-config
    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-facesconfig_2_0.xsd"
    version="2.0">

    <!-- config here -->

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