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

Use the following code snippets:

Bean:

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

@Named(value = "directoryBean")
@ViewScoped
public class DirectoryBean implements Serializable {

private static final long serialVersionUID = 1L;
    ....
}

faces-config.xml

<?xml version="1.0" encoding="UTF-8"?>
<faces-config
    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"
    version="2.3">
     ....
</faces-config>

group.xhtml

<ui:composition ...>

    <f:metadata>
        <f:viewParam name="id" value="#{directoryBean.id}" />
    </f:metadata>

</ui:composition>

The result is an exception:

javax.el.PropertyNotFoundException: /group.xhtml @6,64 value="#{directoryBean.id}": Target Unreachable, identifier 'directoryBean' resolved to null

Got it after changing the syntax of face-config.xml from version 2.2 to version 2.3.

This means that with face-config.xml with the following content, everything works fine:

<faces-config version="2.2" 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_2.xsd">
....
</faces-config>

JSF 2.3.2 is deployed on the Payara 4.1.2.172 (Full) server, and is also added to pom.xml with a "provided" scope.

....
<dependencies>
    ...
    <dependency>
        <groupId>org.glassfish</groupId>
        <artifactId>javax.faces</artifactId>
        <version>2.3.2</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>javax.faces</groupId>
        <artifactId>javax.faces-api</artifactId>
        <version>2.3</version>
        <scope>provided</scope>            
    </dependency>
    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-api</artifactId>
        <version>7.0</version>
        <scope>provided</scope>
    </dependency>
    ...
</dependencies>
....

I checked all the solutions that I managed to find in a few hours, including different versions of beans.xml:

  1. initially beans.xml was not in the project - the problem persists;
  2. added empty beans.xml file - the problem persists;
  3. beans.xml bean-discovery-mode - "" "" - ;

\WEB-INF\beans.xml:

<?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_1_1.xsd"
       bean-discovery-mode="all">
</beans>

Payara 4.1.2.172, GlassFish 5 (java ver 1.8.0_144) Payara 4.1.2.172 (java ver 1.8.0_131).

!

. , https://github.com/AnghelLeonard/JSF-2.3/tree/master/JSF23InjectInConverterValidator, .

+7
4

, , JSF 2.3 JSF v2.3. GlassFish 5.0.

1) JSF libs 2.3.3 ( , jsf 2.3)

2) beans.xml :

<?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 :

<?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) - Java-, JSF 2.3, Jsf23Activator :

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 {

}

@FacesConfig(version = FacesConfig.Version.JSF_2_3) , .

, , , CDI, @ApplicationScoped. , CDI, / - JSF 2.3 - , JSF/ JSF 2.3!

+9

, JSF classpath:

el-impl-2.1.2.jar

.

+1

DirectoryBean :

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

beans.xml bean -discovery-mode "all". faces-config.xml set version 2.3

0
source

Solution 2:

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

0
source

Source: https://habr.com/ru/post/1683708/


All Articles