我在 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
主页.xhtml(类似于"开始.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>
...
开始.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>
步骤2.xhtml(类似于开始.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>
...
步骤3.xhtml(类似于开始.xhtml(
...
<h:form prependId="false">
<h:commandButton id="exit" value="Home" action="exit"/>
</h:form>
...
流名称.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();
}
}
我尝试在起始页退出,这很成功。
网络.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>
它不能很好地工作,因为流页面的名称不以流名称开头。(使用相同的配置(
flowName/
flowName-start.xhtml (or flowName.xhtml the default start page)
flowName-step2.xhtml
...
默认返回页面,例如:flowName-return.xhtml
默认开始或默认返回页不需要任何配置(xml 或带注释的方法(。 查看更多