11

Have 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>

In result getting the exception:

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

Got it after changing faces-config.xml from ver 2.2 to ver 2.3 syntax.

Meaning, with faces-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 deployed on the Payara 4.1.2.172 (Full) server, and also added to pom.xml with "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 have checked all solutions that I was able to find during several hours, including different version of beans.xml:

  1. initially beans.xml was not present in the project - issue persist;
  2. added empty beans.xml - issue persist;
  3. added beans.xml with two different options of bean-discovery-mode - "all" and "annotated" - issue persist;

Content of \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>

Tested on local instances of Payara 4.1.2.172, GlassFish 5 (java ver 1.8.0_144), and remote instance of Payara 4.1.2.172 (java ver 1.8.0_131).

Thanks!

Note: Example projects like this one https://github.com/AnghelLeonard/JSF-2.3/tree/master/JSF23InjectInConverterValidator give the same error.

AndrewG10i
  • 619
  • 1
  • 6
  • 21
  • Did you just change the faces-config? Meaning you were already on a JSF 2.3.2 release and just changed the faces-config? – Kukeltje Aug 15 '17 at 07:26
  • 1
    Yes, exactly! Reverting faces-config back to JSF 2.2 syntax - solves the issue. – AndrewG10i Aug 15 '17 at 07:29
  • A small quick google search resulted in this: https://stackoverflow.com/questions/44064995/jsf-2-3-not-finding-my-named-cdi-1-2-managed-bean. Are you using an 'external' JSF lib too? One provided in your webapp? – Kukeltje Aug 15 '17 at 07:36
  • 1
    Thank you, yep, I also have checked that post and many others... But so far no solution helped. Re your question: on Payara 4.1.2 and GlassFish 4.1.2 - yes, I have manually replaced original JSF 2.2.X javax.faces.jar with JSF 2.3.2 jar. But GlassFish 5 already shipped with JSF 2.3.2 - but there I got the same error... BTW: have found the similar issue in Mojarra issues tracker: https://github.com/javaserverfaces/mojarra/issues/4264 – AndrewG10i Aug 15 '17 at 07:48
  • Please next type post what you tried, read, etc... Saves us time. See also [ask]!!! – Kukeltje Aug 15 '17 at 08:10
  • beans.xml tested with all possible options - added the details about my test with beans.xml. Thank you! – AndrewG10i Aug 15 '17 at 08:33
  • you have this `-->` at the end of your `schemaLocation` is that a typing error? could that be causing the poblem? – David Florez Aug 15 '17 at 20:45
  • yes, thank you, corrected, was just a mistype... – AndrewG10i Aug 16 '17 at 06:23
  • Everyone, any ideas how to fix the issue? ...as it is simply not possible to switch to JSF 2.3... Can somebody share how you deploy your JSF 2.3.X environment, or point to such docs? Thank you! – AndrewG10i Aug 22 '17 at 06:36

4 Answers4

18

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!

Paolo Forgia
  • 5,804
  • 7
  • 39
  • 55
AndrewG10i
  • 619
  • 1
  • 6
  • 21
  • 1
    Thanks, adding the @ApplicationScoped on the activator bean was the crucial step for me. FWIW in my setup (Payara 5.181) I don't have a beans.xml or a faces-config.xml, so I don't think they are strictly necessary. – Martin Charlesworth May 16 '18 at 14:42
  • 1
    While your answer works like a charm this is a ridiculous configuration kerfuffle to use JSF 2.3 features. Thanks for sharing. – Björn Zurmaar Mar 13 '19 at 15:47
2

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

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

Tadas B.
  • 115
  • 7
  • Where did you get this info from? Do you have a link? I'm interested in more of the details. Thanks – Kukeltje Sep 22 '17 at 08:02
  • Thanks! @Kukeltje we had an extensive discussion of this topic here: https://github.com/javaserverfaces/mojarra/issues/4264 – AndrewG10i Sep 23 '17 at 07:25
  • I am trying to set up a JSF 2.3 webapp with the new CDI, but it seems too complicated. No errors are being thrown. https://stackoverflow.com/questions/51255117/my-el-expressions-are-not-being-evaluated-under-a-myfaces-2-3-and-spring-boot-2 – John John Pichler Jul 10 '18 at 20:43
0

Solution 2:

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

usertest
  • 1,658
  • 3
  • 21
  • 34