我正在探索 JSF 2.2 中的 Faces Flow 功能,Target Unreachable, identifier 'flowScope' resolved to null
当我在此页面中运行教程时出现以下错误:http: //www.mastertheboss.com/javaee/jsf/faces-flow-tutorial
该示例似乎非常简单,它只有一个带有 3 个 facelets 的流,具有以下结构:
流程称为signup
,因此我的文件夹中有一个名为signup
in 的WebContent
文件夹和 3 个 facelet,其中一个与流程同名作为起始节点,还有一个名为signup-flow.xml
.
这是起始节点 ( signiup.xhtml
) 的内容:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://xmlns.jcp.org/jsf/facelets" xmlns:f="http://xmlns.jcp.org/jsf/core" xmlns:h="http://xmlns.jcp.org/jsf/html">
<h:head>
<title>Signup account</title>
<meta http-equiv="Content-Type"
content="application/xhtml+xml; charset=UTF-8" />
</h:head>
<h:body>
<h:form id="form1" styleClass="form">
<h1>Signup Account</h1>
<p>Name <h:inputText id="name" value="#{flowScope.name}" /></p>
<p>Surname: <h:inputText id="surname" value="#{flowScope.surname}" /></p>
<p>Email: <h:inputText id="email" value="#{flowScope.email}" /></p>
<p><h:commandButton id="page2" value="next" action="signup2" /></p>
</h:form>
</h:body>
</html>
这是我的SignupBean
:
package com.jsf.flow;
import java.io.Serializable;
import javax.inject.Named;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.faces.flow.FlowScoped;
@Named
@FlowScoped(value="signup")
public class SignupBean implements Serializable {
private static final long serialVersionUID = 8112971305468080981L;
private boolean licenseAccepted;
public SignupBean() {
}
public String getHomeAction() {
return "/index";
}
public boolean isLicenseAccepted() {
return licenseAccepted;
}
public void setLicenseAccepted(boolean licenseAccepted) {
this.licenseAccepted = licenseAccepted;
}
public String accept() {
if (this.licenseAccepted) {
return "signup3";
} else {
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "You have to read and accept the license!", "You have to read and accept the license!"));
return null;
}
}
}
这是我的signup-flow.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_2.xsd"
version="2.2">
<flow-definition id="signup">
<flow-return id="homePage">
<from-outcome>#{signupBean.homeAction}</from-outcome>
</flow-return>
</flow-definition>
</faces-config>
当我单击 中的 时出现错误commandButton
,signup.xhtml
代码似乎与教程中的代码完全相同,我检查了几篇具有相同错误的帖子,但似乎没有什么对我有用。
这是堆栈跟踪中的重要部分:
javax.el.PropertyNotFoundException: /signup/signup.xhtml @12,68 value="#{flowScope.name}": Target Unreachable, identifier 'flowScope' resolved to null
at com.sun.faces.facelets.el.TagValueExpression.getType(TagValueExpression.java:100)
at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getConvertedValue(HtmlBasicInputRenderer.java:95)
值得一提的是,我使用的是 GlassFish 4。