EJB and managed bean injections in @FacesConverter and @FacesValidator in JSF 2.3

@FacesConverterand are @FacesValidatornot suitable for EJBs or bean-guided hover points up to JSF 2.2.

They are supposed to work with JSF 2.3 (only a milestone is currently available ) using the optional attribute managedc @FacesConverterand @FacesValidatoras mentioned here .

In JSF 2.1, very few JSF artifacts were targets for injection. In JSF 2.2, injection was made possible by the sheer number of additional artifacts, but those in which the injection actually matters, converters and validators were mysteriously left in the cold .

In JSF 2.3, this will finally take care of the following artifacts that have been added to the injection target list:

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

However, unlike artifacts already presented on this list, these new 3 are not automatic injection targets. They will become so when the new attribute is “managed” by the corresponding annotations @FacesConverter, @FacesValidatorand @Behaviorset to true. In addition, all of these 3 annotations have been updated to CDI qualifiers by adding annotations @Qualifiedto their definition.

Existing attributes @FacesConverter, @FacesValidatorand have @Behaviornot been changed, which means that they are required, as this is a new attribute "managed".

The attribute managed, however, is not available in Mojarra 2.3.0-m02.

- ? Weld/CDI? GlassFish Server 4.1. ( Weld , , 2.2.2).

+4
1

Mojarra 2.3.0-m02 Application#createConverter() , , JSF 2.3 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 / IDE version.


jdevelopment.nl, , .

+4

All Articles