0

Server: Payara 5.183.

When the converter is used, a NullPointerException is raised because the injected EJB is null (System.out.println prints "null").

It works (injection not null) if I use a workaround used before JSF 2.3: replacement of @FacesConverter by @Name.

Converter:

@FacesConverter(value = "compteConverter", managed = true)
public class CompteConverter implements Converter<CompteBancaire> {

  @EJB
  private GestionnaireCompte gestionnaireCompte;

  @Override
  public CompteBancaire getAsObject(FacesContext context, UIComponent component, String id) {
    if (id == null || id.isEmpty()) {
      return null;
    }
    try {
      System.out.println("*****EJB gestionnaireCompte=" + gestionnaireCompte);
      return gestionnaireCompte.getCompte(Long.parseLong(id));
    } catch (NumberFormatException e) {
      throw new ConverterException(new FacesMessage("Id de compte invalide"), e);
    }
  }

  @Override
  public String getAsString(FacesContext arg0, UIComponent arg1, CompteBancaire compte) { ... }

Usage of this converter:

  <ui:define name="metadata">
    <f:metadata>

      <f:viewParam name="id" value="#{operations.compte}"
                     converter="compteConverter"/>

Is it a bug of Mojarra/Payara (managed = true is not working) or can you help me to find my error?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
user1643352
  • 2,635
  • 2
  • 19
  • 25
  • The version declared in faces-config.xml is correctly 2.3. – user1643352 Sep 26 '18 at 07:20
  • A project on GIT-HUB to reproduce the problem: https://github.com/richard-grin/testConverter2. You can change the definition of the database in the class AccountManager. To reproduce the problem, edit AccountConverter to use @FacesConverter and not Named and RequestScoped, and operations.xhtml to use the converterId in – user1643352 Oct 01 '18 at 20:26

1 Answers1

2

Managed converters don't work by default. To make them work I added a CDI bean annotated by @FacesConfig (for JSF 2.3 to be used) and @ApplicationScoped (it will be a CDI bean with this annotation).

user1643352
  • 2,635
  • 2
  • 19
  • 25
  • This works. I needed to add the steps described here though: https://stackoverflow.com/questions/45682309/changing-faces-config-xml-from-2-2-to-2-3-causes-javax-el-propertynotfoundexcept – Uwe Bretschneider Jul 24 '19 at 16:55
  • I'll check again but I needn't any extra steps except adding the CDI bean annotated by @ApplicationScoped. – user1643352 Jul 25 '19 at 17:19