gpt4 book ai didi

jsf - JSF 2.3 中 @FacesConverter 和 @FacesValidator 中的 EJB 和托管 bean 注入(inject)

转载 作者:行者123 更新时间:2023-12-03 12:10:44 25 4
gpt4 key购买 nike

@FacesConverter@FacesValidator不符合 EJB 或最高 JSF 2.2 的托管 bean 注入(inject)点的条件。

它们应该使用附加的 managed 与 JSF 2.3(目前仅作为 milestone 可用)一起使用。 @FacesConverter 的属性和 @FacesValidator如前所述here .

In JSF 2.1 very few JSF artifacts were injection targets. In JSF 2.2 injection was made possible in a huge amount of additional artefacts but the very ones where injection actually matters most, converters and validators, were mysteriously left in the cold.

In JSF 2.3 this has now finally been taken care of as the following artefacts have been added to the list of injection targets:

  • javax.faces.convert.Converter
  • javax.faces.validator.Validator
  • javax.faces.component.behavior.Behavior

However, in contrast to the artefacts already on this list these new 3 are not automatically injection targets. They will only become so when a new attribute called "managed" on the corresponding annotations @FacesConverter, @FacesValidator and @Behavior is set to true. Furthermore all these 3 annotations have been upgraded to being CDI qualifiers by adding the @Qualified annotation to their definition.

The existing attributes of @FacesConverter, @FacesValidator and @Behavior have not been modified, meaning they are all binding, as is the new attribute "managed".



属性 managed但是,在 Mojarra 2.3.0-m02 中不可用。

是因为里程碑吗?它是否依赖于特定的 Weld/CDI 版本?我目前正在使用 GlassFish Server 4.1。提到了不同的神器版本 here (服务器版本提供的默认 Weld 版本是 2.2.2 final)。

最佳答案

正如您在 Mojarra 2.3.0-m02 的 Application#createConverter() implementation 中看到的那样, 它checks if it's running in JSF 2.3 mode根据 faces-config.xml version在尝试获取 CDI 管理的之前声明。

也就是说,为了得到@FacesConverter(managed=true) , @FacesValidator(managed=true)因此@Inject在这些类中工作,你需要确保你的 webapp 的 faces-config.xml声明符合 JSF 2.3 如下:

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

<!-- Config here. -->

</faces-config>

需要注意的是,IDE 可能会在 JSF 2.3 XSD 上出错。文件尚未公开可用,您可以放心地忽略该部分,JSF 在运行时不会对其进行验证。您也可以坚持使用 2.2 XSD 并忽略不受支持的 version 上的任何 IDE 警告/错误。 .

jdevelopment.nl 博客作者已收到通知,他将确保在下一次更新中,上述内容也会在博客中得到澄清。

关于jsf - JSF 2.3 中 @FacesConverter 和 @FacesValidator 中的 EJB 和托管 bean 注入(inject),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30028197/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com