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

The @FacesValidator, @FacesComponent, @FacesConverter and @FacesBehavior injection is not supported #4645

Closed
caim2015 opened this issue Oct 14, 2019 · 5 comments
Labels

Comments

@caim2015
Copy link

Environment Details

  • GlassFish Version (and build number):V5.1
  • JDK version:8
  • OS:windows or linux
  • Database:none

Problem Description

I referenced the following link to build a java test.
https://github.com/javaserverfaces/mojarra/blob/2.2.7/jsf-ri/systest/src/com/sun/faces/annotation/AnnotatedValidator.java

The test code is shown as following.


@FacesValidator(value = "AnnotatedValidator")
public class AnnotatedValidator implements Validator {

    public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
        return;
    }

    @Resource(name = "welcomeMessage")
    private String welcomeMessage;      

    public String getWelcomeMessage() {
        return "AnnotatedValidator " + welcomeMessage;
    }

    @PostConstruct
    public void preInit() {
        System.out.println("@PostConstruct from AnnotatedValidator");    
    }

}

I run the test code in GlassFish4.1(JSF 2.2.7), and turns out that it can get the value of "welcomeMessage" which is defined in web.xml by using the @resource.
However, I run the same code in GlassFish5.1(JSF 2.3.9), there is no value setted for the "welcomeMessage"."welcomeMessage" becomes null.

It's the same result when I use @FacesComponent, @FacesConverter or @FacesBehavior annotation in java test code.

Now that, I have the question:
Why the @FacesValidator, @FacesComponent, @FacesConverter and @FacesBehavior injection is not supported in GlassFish5.1?

@tandraschko
Copy link
Contributor

You need @FacesValidator(..., managed=true). If that works, please close the issue here.

@caim2015
Copy link
Author

You need @FacesValidator(..., managed=true). If that works, please close the issue here.

Thank you for your reply!
I hava tried it.It doesn't work.

@caim2015
Copy link
Author

caim2015 commented Oct 31, 2019

Hi,I think I found the reason.
Starting from the JSF2.2.8-04, the following code was deleted.

https://github.com/javaserverfaces/mojarra/commit/93011dc57a07063094d70906dae12ec760904614#diff-92a6ce2db2d9b6ac520aea86b4fcaf84
com/sun/faces/application/ApplicationImpl.java

if (map.hasAnnotations(key)) {
            InjectionProvider injectionProvider = associate.getInjectionProvider();
            try {
                injectionProvider.invokePostConstruct(result);
            } catch (InjectionProviderException ex) {
               LOGGER.log(Level.SEVERE, "Unable to invoke @PostConstruct annotated method on instance " + key, ex);
               throw new FacesException(ex);
            }

            try {
                injectionProvider.inject(result);
            } catch (InjectionProviderException ex) {
               LOGGER.log(Level.SEVERE, "Unable to inject instance" + key, ex);
               throw new FacesException(ex);
            }
        }

But,I'm not sure why it was deleted .
Please give some thoughts on this.

@chris21k
Copy link

chris21k commented Jan 9, 2020

There is the (old) open bug entry #4245 about that. This thread also contains a workaround (Jul 30, 2017). However, it would be nice to have a real fix.

Chris

@mnriem
Copy link
Contributor

mnriem commented Sep 2, 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 2, 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

4 participants