将faces-config.xml从2.2更改为2.3会导致javax.el.PropertyNotFoundException:无法到达目标,标识符"bean"解析为null [英] Changing faces-config.xml from 2.2 to 2.3 causes javax.el.PropertyNotFoundException: Target Unreachable, identifier 'bean' resolved to null

查看:98
本文介绍了将faces-config.xml从2.2更改为2.3会导致javax.el.PropertyNotFoundException:无法到达目标,标识符"bean"解析为null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

具有以下代码段:

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

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

group.xhtml

<ui:composition ...>

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

</ui:composition>

结果得到异常:

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

在将faces-config.xml从2.2版语法更改为2.3版语法后得到了它.

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

意思是,使用带有以下内容的faces-config.xml,一切正常:

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部署在Payara 4.1.2.172(完整)服务器上,并且还添加到pom.xml中,具有提供的"范围.

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

我已经检查了几个小时内能够找到的所有解决方案,包括不同版本的bean.xml:

I have checked all solutions that I was able to find during several hours, including different version of beans.xml:

  1. 项目中最初不存在beans.xml-问题 坚持;
  2. 添加了空的beans.xml-问题仍然存在;
  3. 使用两个不同的bean-discovery-mode选项添加了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;

\ WEB-INF \ beans.xml的内容:

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>

在Payara 4.1.2.172,GlassFish 5(Java版本1.8.0_144)和Payara 4.1.2.172(Java版本1.8.0_131)的远程实例上进行了测试.

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).

谢谢!

注意:像这样的示例项目 https://github.com/AnghelLeonard /JSF-2.3/tree/master/JSF23InjectInConverterValidator 给出相同的错误.

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

推荐答案

我想发布一个完整的解决方案,为了使JSF 2.3库能够在JSF v2.3模式下工作,应该做什么.下面的代码示例基于GlassFish 5.0服务器环境.

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)至少将JSF库升级到版本2.3.3(它修复了与jsf 2.3模式激活有关的一些错误)

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

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并且内容绝对为空:

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 {

}

注释@FacesConfig(version = FacesConfig.Version.JSF_2_3)每个项目添加一次,无需多次添加.

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

基本上,其他人多次提到添加此批注的需要,但是在我的情况下,直到我通过添加批注@ApplicationScoped将该类声明为CDI bean时,它才起作用.只有在我将该类声明为CDI bean之后,才清除项目/重新启动服务器-终于激活了JSF 2.3模式,现在我可以注入JSF类/利用其他JSF 2.3功能了!

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!

这篇关于将faces-config.xml从2.2更改为2.3会导致javax.el.PropertyNotFoundException:无法到达目标,标识符"bean"解析为null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆