And*_*-Gr 7 jsf faces-config cdi jsf-2.3 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;
....
}
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)
group.xhtml
<ui:composition ...>
<f:metadata>
<f:viewParam name="id" value="#{directoryBean.id}" />
</f:metadata>
</ui:composition>
Run Code Online (Sandbox Code Playgroud)
结果得到异常:
javax.el.PropertyNotFoundException: /group.xhtml @6,64 value="#{directoryBean.id}": Target Unreachable, identifier 'directoryBean' resolved to null
Run Code Online (Sandbox Code Playgroud)
在将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>
Run Code Online (Sandbox Code Playgroud)
JSF 2.3.2部署在Payara 4.1.2.172(完整)服务器上,并且还添加到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>
....
Run Code Online (Sandbox Code Playgroud)
我检查了几个小时内可以找到的所有解决方案,包括不同版本的beans.xml:
\ 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>
Run Code Online (Sandbox Code Playgroud)
在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给出了相同的错误。
And*_*-Gr 10
我想发布一个完整的解决方案,为了使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>
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)
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 {
}
Run Code Online (Sandbox Code Playgroud)
@FacesConfig(version = FacesConfig.Version.JSF_2_3)
每个项目注释一次添加,无需多次添加。
基本上,其他人多次提到添加此批注的需要,但是在我的情况下,直到我通过添加注解将该类声明为CDI bean时,它才起作用@ApplicationScoped
。只有在我将该类声明为CDI bean之后,才清除项目/重新启动服务器-最终激活了JSF 2.3模式,现在我可以注入JSF类/利用其他JSF 2.3功能了!
归档时间: |
|
查看次数: |
6278 次 |
最近记录: |