1

我正在尝试开发一个简单的 JSF 2.2 新功能示例,@FlowScope,我使用 eclipse luna,glassfish 4.0 开发它,我猜代码是正确的,因为我在网上发现了它,可能错误与配置有关的项目。谁能给我一个可能是什么的想法?请向我询问更多信息,如果这些信息很难理解,但实际上我不知道我还能写些什么来提供帮助,这是我在 stackoverflow 上的第一个问题。

public class NestedFlowBuilder implements Serializable {

    private static final long serialVersionUID = 1L;    
    @Produces
    @FlowDefinition
    public Flow defineCallingFlow
    (@FlowBuilderParameter FlowBuilder flowBuilder) {
    String flowId = "secondJavaFlow";
    flowBuilder.id("", flowId);
    flowBuilder.viewNode(flowId, "/java-calling-flow/start-page.xhtml")
    .markAsStartNode();
    flowBuilder.viewNode("results", 
    "/java-calling-flow/results-page.xhtml");
    flowBuilder.returnNode("return").fromOutcome("/return-page-for-java-calling-flow");   
    flowBuilder.returnNode("home").fromOutcome("/index");
    flowBuilder.flowCallNode("go-to-nested")
    .flowReference("", "thirdJavaFlow")
    .outboundParameter("paramForNestedFlow", 
    "#{javaCallingFlowBean.param1}");
    return(flowBuilder.getFlow());
    }



    @Produces
    @FlowDefinition
    public Flow defineNestedFlow
    (@FlowBuilderParameter FlowBuilder flowBuilder) {
    String flowId = "thirdJavaFlow";
    flowBuilder.id("", flowId);
    flowBuilder.viewNode(flowId, 
    "/java-nested-flow/start-page.xhtml")
    .markAsStartNode();
    flowBuilder.viewNode("results", 
    "/java-nested-flow/results-page.xhtml");
    flowBuilder.returnNode("return-to-previous-start")
    .fromOutcome("secondJavaFlow"); 
    flowBuilder.returnNode("return-to-previous-results")
    .fromOutcome("results");
    flowBuilder.inboundParameter("paramForNestedFlow", 
    "#{javaNestedFlowBean.param3}");
    return(flowBuilder.getFlow());
    }

package coreservlets;

import java.io.Serializable;

import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.faces.flow.FlowScoped;
import javax.inject.Named;


@Named
@FlowScoped("thirdJavaFlow")
public class JavaNestedFlowBean implements Serializable {

    private static final long serialVersionUID = 1L;
    private String param3, param4;

    public String doFlow() {
    if (param3.equalsIgnoreCase(param4)) {
    FacesContext context = FacesContext.getCurrentInstance();
    FacesMessage fMessage = 
    new FacesMessage("Params must be distinct");
    fMessage.setSeverity(FacesMessage.SEVERITY_ERROR);
    context.addMessage(null, fMessage);
    return(null);
    } else {
    return("results");
    }
    }

    public String getParam3() {
        return param3;
    }
    public void setParam3(String param3) {
        this.param3 = param3;
    }

    public String getParam4() {
        return param4;
    }

    public void setParam4(String param4) {
        this.param4 = param4;
    }

    public static long getSerialversionuid() {
        return serialVersionUID;
    }
    }

<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Java Calling Flow Start PAge</title>
</head>
<body>
<h:form>
<h:messages globalOnly="true" styleClass="error"/>
<h:panelGrid columns="3" styleClass="formTable">
Param 1: 
<h:inputText value="#{javaCallingFlowBean.param1}" id="param1"
required="true"
requiredMessage="Param 1 is required"/>
<h:message for="param1" styleClass="error"/>
Param 2: 
<h:inputText value="#{javaCallingFlowBean.param2}" id="param2"
required="true"
requiredMessage="Param 2 is required"/>
<h:message for="param2" styleClass="error"/>
<f:facet name="footer">
<h:commandButton value="Show Results"
action="#{javaCallingFlowBean.doFlow}"/><br/>
</f:facet>
</h:panelGrid>
</h:form>
</body>
</html>

我收到此错误:

javax.el.ELException: /java-calling-flow/start-page.xhtml @17,40 value="#{javaCallingFlowBean.param1}": org.jboss.weld.context.ContextNotActiveException: WELD-001303 No active contexts for scope type javax.faces.flow.FlowScoped

http://courses.coreservlets.com/Course-Materials/pdf/jsf/jsf2/JSF-2.2-Faces-Flow-2.pdf 来自第 33 页

4

0 回答 0