Search code examples
jsfjsf-2.2faces-flow

Can't return from Flow


I created a simple flow in JSF but I can't exit at the 2. page or 3. page. I use @FlowDefinition to specify start page and end/return page.

Error message: Unable to find matching navigation case with from-view-id '/flowname/step3.xhtml' for action 'exit' with outcome 'exit'

I use WildFly 16 on Ubuntu 18.04

home.xhtml (similar to 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 (similar to 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 (similar to 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();
    }
}

I tried to exit at start page and that was successful.

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>

Solution

  • It don't work well, because the name of the flow pages don't start with the flow name. (With same config)

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

    The default return page e.g.: flowName-return.xhtml Don't need any config (xml or annotated method) for default start or default return page. See more