2017-08-14 108 views
3

有以下代码片段:更改faces-config.xml中从2.2至2.3的原因javax.el.PropertyNotFoundException:目标不可达,识别符 '豆' 解析为空

豆:

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

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

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

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

在结果得到异常:

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

得到它从版本2.2改变faces-config.xml中为版本2.3句法之后。

含义,与faces-config.xml中有以下内容一切正常:部署似鲭水狼牙鱼4.1.2.172(全)服务器上,也

<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加入的pom.xml与“提供”范围。

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

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

  1. 最初的beans.xml是不存在的项目 - 问题 坚持;
  2. 添加空beans.xml - 问题持续;
  3. 添加beans.xml,其中包含bean-discovery-mode的两个不同选项 - “all” 和“注释” - 问题依然存在; \ 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> 

在测试了似鲭水狼牙鱼4.1.2.172,GlassFish的5(java的版1.8.0_144)的本地实例,和似鲭水狼牙鱼4.1的远程实例.2.172(java ver 1.8.0_131)。

谢谢!

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

+0

你只需要改变的面孔,配置?这意味着你已经在JSF 2.3.2发行版中,只是改变了faces-config? – Kukeltje

+1

是的,确切!将faces-config恢复为JSF 2.2语法 - 解决了这个问题。 –

+0

一个小的快速谷歌搜索结果中的:https://stackoverflow.com/questions/44064995/jsf-2-3-not-finding-my-named-cdi-1-2-managed-bean。你是否也在使用“外部”JSF库?一个在你的webapp中提供? – Kukeltje

回答

1

我想发布一个完整的解决方案,应该做什么才能使JSF 2.3库在JSF v2.3模式下工作。以下代码示例基于GlassFish 5.0服务器环境。 1)至少将JSF库升级到版本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)和关键球员在这一切的设置 - 是特别是形成实际激活JSF 2.3模式的Java类,在我的情况下,它的名字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)加一次每个项目,没有必要添加了好几遍。

基本上需要添加这个注解被其他人多次提到,但在我的情况下,它不工作,直到我通过添加注释@ApplicationScoped将这个类声明为CDI bean。只有在我将该类声明为CDI bean后,清除了项目/重新启动的服务器 - JSF 2.3模式最终被激活,现在我能够注入JSF类/利用其他JSF 2.3功能!

谢谢!

0

在DirectoryBean加入这一行:

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

,并在beans.xml变化豆的发现模式为 “全部”。 faces-config.xml设置版本2.3

+0

你从哪里得到这些信息?你有链接吗?我对更多细节感兴趣。谢谢 – Kukeltje

+0

谢谢! @Kukeltje我们在这里对这个主题进行了广泛的讨论:https://github.com/javaserverfaces/mojarra/issues/4264 –

相关问题