Changing faces-config.xml from 2.2 to 2.3 causes javax.el.PropertyNotFoundException: Target Unreachable, identifier 'bean' resolved to null

后端 未结 4 1964
遇见更好的自我
遇见更好的自我 2020-12-01 23:51

Have the following code snippets:

Bean:

import javax.faces.view.ViewScoped;
import javax.inject.Named;

@Named(value = \"directoryBean\")
@ViewScoped         


        
4条回答
  •  自闭症患者
    2020-12-02 00:33

    I would like to post a complete solution, what should be done in order to make JSF 2.3 libs work in JSF v2.3 mode. Code samples below are based on GlassFish 5.0 server environment.

    1) Upgrade JSF libs to the version 2.3.3 at least (it fixes some bugs related to jsf 2.3 mode activation)

    2) The beans.xml should look like:

    
    
    
    

    3) faces-config.xml should look like:

    
    
        ....
    
    

    4) And the key-player in all this setup - is specially formed Java class that actually activates JSF 2.3 mode, in my case it has name Jsf23Activator and absolutely empty content:

    package ua.local.beans;
    
    import javax.enterprise.context.ApplicationScoped;
    import javax.faces.annotation.FacesConfig;
    
    @ApplicationScoped
    @FacesConfig(version = FacesConfig.Version.JSF_2_3)
    public class Jsf23Activator {
    
    }
    

    The annotation @FacesConfig(version = FacesConfig.Version.JSF_2_3) is added once per project, no need to add it several times.

    Basically the need to add this annotation was mentioned several times by others, but in my case it didn't work until I declared this class as CDI bean by adding annotation @ApplicationScoped. Only after I declared the class as CDI bean, cleared project / restarted server - the JSF 2.3 mode finally got activated and now I am able to inject JSF classes / utilize other JSF 2.3 features!

提交回复
热议问题