Search code examples
jsfnullconvertersinjectmojarra

@Inject doesn't work in @FacesConverter after upgrade GlassFish 4.1 to 4.1.1


I have a problem with GlassFish 4.1.1 and Payara 4.1.153+.

The @Inject points in the POJO converters no longer work. What did I miss? Has something changed in FacesConverter?

@FacesConverter("bkkConverter")
public class BkkConverter implements Converter,Serializable
{

  @Inject
  private BkkBean bkkBean;
  ...
  bkkBean.fetchFromDatabase(...); <- NPE

The variable bkkBean remains null now. The Converter itself works (getAsObject/getAsString), but no @Inject?

It still works on GlassFish 4.1.


Solution

  • You were relying on an unspecified/undocumented feature. Mojarra 2.2 unintentionally supported @Inject in @FacesConverter, @FacesValidator and @FacesComponent before version 2.2.9 as consequence of a forgotten experiment/rollback. The support is expected to come in Mojarra 2.3 whereby an additional annotation attribute is required as in @FacesConverter(managed=true). See also a.o. issue 3552.

    In JSF 2.2 with CDI 1.1 your best bet is to manually grab the bean via CDI utility class.

    BkkBean bkkBean = CDI.current().select(BkkBean.class).get();
    // ...
    

    Alternatively, you can install OmniFaces in order to get transparent support for @Inject (and @EJB) in @FacesConverter and @FacesValidator

    See also: