0

JSF 2.2 の Faces Flow 機能を調査していますがTarget Unreachable, identifier 'flowScope' resolved to null、このページのチュートリアルを実行すると次のエラーが発生します: http://www.mastertheboss.com/javaee/jsf/faces-flow-tutorial

サンプルは非常に単純に見えます。3 つの facelets を持つ 1 つのフローしかなく、次の構造になっています。

ここに画像の説明を入力

フローは と呼ばれるsignupので、フォルダーsignup内に inと呼ばれるフォルダーと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>

をクリックするとエラーが発生しますcommandButtonsignup.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を使用していることに言及する価値があります。

4

1 に答える 1

0

Found the problem, I was trying to start the flow calling the initial node using a link, like this:

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

Instead I replaced the link with a commandButton and in the action parameter I used the flow name, like this:

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

And now it's working.

于 2015-01-29T21:59:04.340 に答える