Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2.3.14: @FacesConverter injection with CDI is not supported - NPE #5110

Closed
Toru47 opened this issue Jun 1, 2022 · 1 comment
Closed

2.3.14: @FacesConverter injection with CDI is not supported - NPE #5110

Toru47 opened this issue Jun 1, 2022 · 1 comment
Labels

Comments

@Toru47
Copy link

Toru47 commented Jun 1, 2022

CDI is not working as expected in custom FacesConverter despite set to managed = true. The injected member keeps null:

ApplicationBean.java:

package foo.bar;

import javax.enterprise.context.ApplicationScoped;
import javax.faces.annotation.FacesConfig;

@FacesConfig(version = FacesConfig.Version.JSF_2_3)
@ApplicationScoped
public class ApplicationBean {
}

ComDateConverter.java:

package foo.bar.common.converters;
 
import java.util.Objects;
 
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.DateTimeConverter;
import javax.faces.convert.FacesConverter;
import javax.inject.Inject;
 
import org.jboss.logging.Logger;
 
@FacesConverter(value = "comDateTimeConverter", managed = true) // <-- CDI should work!
public class ComDateTimeConverter extends DateTimeConverter {
    @Inject
    private Logger logger; // <-- Keeps null.
 
    @Override
    public Object getAsObject(FacesContext context, UIComponent component,
            String newDateAsString) {
        Objects.requireNonNull(logger); // <-- NPE!
        return super.getAsObject(context, component, newDateAsString);
    }
}

faces-config.xml:

<converter>
    <converter-id>javax.faces.DateTime</converter-id>
    <converter-class>foo.bar.common.converters.ComDateTimeConverter</converter-class>
</converter>

test.xhtml

<h:inputText ...
  <f:convertDateTime ...

Or is this issue also fixed with #5075?

Tests with WildFly 21.0.0.Final and JDK 11.0.3.

@Toru47 Toru47 changed the title 2.3.14: @FacesConverter injection is not supported - NPE 2.3.14: @FacesConverter injection with CDI is not supported - NPE Jun 1, 2022
@mnriem mnriem added the 2.3 label Sep 5, 2023
@mnriem
Copy link
Contributor

mnriem commented Sep 7, 2023

For Mojarra 2.3 and earlier please contact your vendor for support (RedHat, IBM, Oracle, Omnifish, Payara, etceteras)

@mnriem mnriem closed this as completed Sep 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants