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

后端 未结 4 1949
遇见更好的自我
遇见更好的自我 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:25

    Solution 2:

    switch to Payara 5.183, it works out of the box. No need for solution 1: Jsf23Activator

    0 讨论(0)
  • 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:

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_2_0.xsd"
       bean-discovery-mode="all" version="2.0">
    </beans>
    

    3) faces-config.xml should look like:

    <?xml version='1.0' encoding='UTF-8'?>
    <faces-config version="2.3"
              xmlns="http://xmlns.jcp.org/xml/ns/javaee"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_3.xsd">
        ....
    </faces-config>
    

    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!

    0 讨论(0)
  • 2020-12-02 00:35

    I had this problem because after the update of JSF i still had this jar in my classpath :

    el-impl-2.1.2.jar

    After deleting this one the problem went away.

    0 讨论(0)
  • 2020-12-02 00:42

    in DirectoryBean add this line:

    // Activates CDI build-in beans
     @FacesConfig(
             version = JSF_2_3
    )
    

    and in beans.xml change bean-discovery-mode to "all". faces-config.xml set version 2.3

    0 讨论(0)
提交回复
热议问题