【发布时间】:2023-04-03 09:50:01
【问题描述】:
有如下代码sn-ps:
豆子:
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>
得到异常的结果:
javax.el.PropertyNotFoundException: /group.xhtml @6,64 value="#{directoryBean.id}": Target Unreachable, identifier 'directoryBean' resolved to null
将 faces-config.xml 从 2.2 版更改为 2.3 版语法后得到它。
意思是,带有以下内容的 faces-config.xml 一切正常:
<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 (Full) 服务器上,并且还以“提供”范围添加到 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:
- 最初项目中不存在 beans.xml - 问题 坚持;
- 添加了空 beans.xml - 问题仍然存在;
- 添加了 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>
在 Payara 4.1.2.172、GlassFish 5(java 版本 1.8.0_144)和 Payara 4.1.2.172 远程实例(java 版本 1.8.0_131)的本地实例上测试。
谢谢!
注意:像 https://github.com/AnghelLeonard/JSF-2.3/tree/master/JSF23InjectInConverterValidator 这样的示例项目会给出相同的错误。
【问题讨论】:
-
你刚刚改变了 faces-config 吗?这意味着您已经在 JSF 2.3.2 版本上,只是更改了 faces-config?
-
是的,完全正确!将 faces-config 恢复为 JSF 2.2 语法 - 解决了这个问题。
-
一个小的快速谷歌搜索结果如下:stackoverflow.com/questions/44064995/…。您是否也在使用“外部”JSF 库?一个在您的网络应用中提供?
-
谢谢你,是的,我也检查了那个帖子和许多其他的......但到目前为止没有任何解决方案有帮助。关于您的问题:在 Payara 4.1.2 和 GlassFish 4.1.2 上 - 是的,我已经手动将原始 JSF 2.2.X javax.faces.jar 替换为 JSF 2.3.2 jar。但是 GlassFish 5 已经随 JSF 2.3.2 一起发布了——但是我遇到了同样的错误......顺便说一句:在 Mojarra 问题跟踪器中发现了类似的问题:github.com/javaserverfaces/mojarra/issues/4264
-
接下来请输入您尝试过的内容、阅读过的内容等...节省我们的时间。另见How to Ask!!!
标签: jsf cdi faces-config propertynotfoundexception jsf-2.3