无法从Flow返回

时间:2019-08-08 01:41:28

标签: jsf jsf-2.2 faces-flow

我在JSF中创建了一个简单的流程,但是无法退出2.页面或3.页面。 我使用@FlowDefinition指定开始页面和结束/返回页面。

错误消息: Unable to find matching navigation case with from-view-id '/flowname/step3.xhtml' for action 'exit' with outcome 'exit'

我在Ubuntu 18.04上使用WildFly 16

home.xhtml(类似于start.xhtml)

...
    <body jsf:id="body">
        <h1>Flow with JSF 2.2</h1>

        <h:form prependId="false">
            <p>To start the flow:</p>
            <h:commandButton value="Click here!" action="flowName"/>
        </h:form>
    </body>
...

start.xhtml

<!DOCTYPE html>
<html lang="en"
        xmlns="http://www.w3.org/1999/xhtml"
        xmlns:jsf="http://xmlns.jcp.org/jsf"
        xmlns:h="http://xmlns.jcp.org/jsf/html"
        xmlns:c="http://xmlns.jcp.org/jsf/core">
    <head jsf:id="head">
        <meta charset="UTF-8"/>
        <title>In Flow</title>
    </head>

    <body jsf:id="body">
        <h1>In Flow</h1>

        <h:form prependId="false">

            <!-- step2.xhtml -->
            <h:commandButton id="next" value="Next" action="step2"/>
            <h:commandButton id="exit" value="Home" action="exit"/>
        </h:form>
    </body>
</html>

step2.xhtml(类似于start.xhtml)

...
        <h:form prependId="false">


            <h:commandButton id="back" value="Back" action="start"/>
            <h:commandButton id="next" value="Finish" action="step3"/>
            <h:commandButton id="exit" value="Home" action="exit"/>
        </h:form>
...

step3.xhtml(类似于start.xhtml)

...
        <h:form prependId="false">

            <h:commandButton id="exit" value="Home" action="exit"/>
        </h:form>
...

FlowName.java

public class FlowName {
    public static final String NAME = "flowName";
    public static final String EXIT = "exit";

    private static final String START_PATH = "/flowname/start.xhtml";
    private static final String EXIT_CMD = "/home";

    @Produces
    @FlowDefinition
    public Flow defineFlow(@FlowBuilderParameter FlowBuilder flowBuilder) {

        flowBuilder.id("", NAME);
        //start the flow
        flowBuilder.viewNode(NAME, START_PATH).markAsStartNode();

        //exit from flow
        flowBuilder.returnNode(EXIT).fromOutcome(EXIT_CMD);

        return flowBuilder.getFlow();
    }
}

我试图退出起始页,但成功。

web.xml

<web-app 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-app_4_0.xsd"
    version="4.0">

    <display-name>Flow with JSF 2.2</display-name>

    <welcome-file-list>
        <welcome-file>/home.xhtml</welcome-file>
    </welcome-file-list>

    <context-param>
        <param-name>javax.faces.PROJECT_STAGE</param-name>
        <!-- Info: https://javaee.github.io/tutorial/jsf-configure013.html#GIQXL -->
        <param-value>Development</param-value>
    </context-param>

    <context-param>
        <!-- it is disabled default -->
        <param-name>javax.faces.CLIENT_WINDOW_MODE</param-name>
        <param-value>url</param-value>
    </context-param>

    <servlet>
      <servlet-name>JSF</servlet-name>
      <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
      <load-on-startup>1</load-on-startup>
    </servlet>

    <!-- hidden resources folder for JSF -->
    <context-param>
      <param-name>
        javax.faces.WEBAPP_RESOURCES_DIRECTORY
      </param-name>
      <param-value>/WEB-INF/resources</param-value>
    </context-param>

    <servlet-mapping>
      <servlet-name>JSF</servlet-name>
      <url-pattern>*.xhtml</url-pattern>

      <url-pattern>/home</url-pattern>
    </servlet-mapping>

</web-app>

1 个答案:

答案 0 :(得分:0)

它不能很好地工作,因为流程页面的名称不是以流程名称开头的。 (使用相同的配置)

flowName/
    flowName-start.xhtml (or flowName.xhtml the default start page)
    flowName-step2.xhtml
    ...

默认返回页面,例如:flowName-return.xhtml 默认开始页面或默认返回页面不需要任何配置(xml或带注释的方法)。 See more