目标无法访问,标识符' flowScope'解析为null

时间:2015-01-29 19:49:17

标签: jsf jsf-2.2 faces-flow

我正在探索JSF 2.2中的Faces Flow功能,当我在此页面中运行教程时,我收到以下错误Target Unreachable, identifier 'flowScope' resolved to nullhttp://www.mastertheboss.com/javaee/jsf/faces-flow-tutorial

样本似乎非常简单,它只有一个包含3个facelets的流,具有以下结构:

enter image description here

该流程称为signup,因此我的signup文件夹中有一个名为WebContent的文件夹,还有3个facelets,其中一个与流程名称相同节点和名为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.

1 个答案:

答案 0 :(得分:0)

发现问题,我试图使用链接启动流程调用初始节点,如下所示:

<h:link id="link1" styleClass="link" value="Link" outcome="/signup/signup.xhtml"></h:link>

相反,我用commandButton替换了链接,在action参数中我使用了流名称,如下所示:

<h:commandButton id="start" value="Signup User" action="signup"/>

现在它正在工作。