首页 > 解决方案 > 使用 Spring Web 流 + JSF 不会在流中捕获动作事件

问题描述

流程正在运行,我可以启动它并访问第一个视图状态激活,但是当我按下它应该触发动作事件以转换到下一个状态的按钮时,它不起作用。我尝试了许多解决方案来触发activation.xhtml成功)中的动作事件,但没有一个有效。我想我缺少将 JSF 与 Spring Web Flow 集成的配置。

web.xml包含两个 servlet(Dispatcher + jsf):

<?xml version="1.0" encoding="UTF-8"?>
<web-app>

    <servlet>
        <servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/web-application-config.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    
    <servlet-mapping>
        <servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
        <url-pattern>/spring/*</url-pattern>
    </servlet-mapping>
    
    <!-- Just here so the JSF implementation can initialize, *not* used at runtime -->
    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    
    <!-- Just here so the JSF implementation can initialize -->
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.faces</url-pattern>
    </servlet-mapping>

    <!-- Use JSF view templates saved as *.xhtml, for use with Facelets -->
    <context-param>
        <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
        <param-value>.xhtml</param-value>
    </context-param>

</web-app>

网络应用程序配置.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns:context="http://www.springframework.org/schema/context"
         xmlns:faces="http://www.springframework.org/schema/faces"
         xsi:schemaLocation="
             http://www.springframework.org/schema/beans
             http://www.springframework.org/schema/beans/spring-beans.xsd
             http://www.springframework.org/schema/context
             http://www.springframework.org/schema/context/spring-context-4.0.xsd
             http://www.springframework.org/schema/faces
             http://www.springframework.org/schema/faces/spring-faces.xsd">
             
    <bean class = "org.springframework.web.servlet.view.InternalResourceViewResolver">
       <property name = "prefix" value = "/WEB-INF/views/"/>
       <property name = "suffix" value = ".jsp"/>
    </bean>
    
    <faces:resources />
    <context:component-scan base-package="sign" />
    
    <bean class="org.springframework.faces.webflow.JsfFlowHandlerAdapter">
        <property name="flowExecutor" ref="flowExecutor" />
    </bean>
    <import resource="flow-definition.xml"/>

</beans>

流定义:

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:webflow="http://www.springframework.org/schema/webflow-config"
    xmlns:faces="http://www.springframework.org/schema/faces"
    xsi:schemaLocation="http://www.springframework.org/schema/webflow-config
        http://www.springframework.org/schema/webflow-config/spring-webflow-config.xsd
        http://www.springframework.org/schema/beans 
        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/faces
        http://www.springframework.org/schema/faces/spring-faces.xsd">
    <!-- Executes flows: the central entry point into the Spring Web Flow system --> 
    
    <bean class="org.springframework.webflow.mvc.servlet.FlowHandlerMapping">
        <property name="flowRegistry" ref="flowRegistry" />
        <property name="order" value="0"/>
    </bean>
  
    <bean class="org.springframework.webflow.mvc.servlet.FlowHandlerAdapter">
        <property name="flowExecutor" ref="flowExecutor" />
    </bean>
    
    <webflow:flow-executor id="flowExecutor">
        <webflow:flow-execution-listeners>
            <webflow:listener ref="facesContextListener"/>
        </webflow:flow-execution-listeners>
    </webflow:flow-executor>

    <!-- The registry of executable flow definitions -->
    <webflow:flow-registry id="flowRegistry" flow-builder-services="flowBuilderServices" >
        <webflow:flow-location  id="signature"  path="/WEB-INF/flows/creation/naturalperson/create-natural-person-flow.xml" />
        <webflow:flow-location id="learning" path="/WEB-INF/flows/learning/learning-flow.xml"/>
    </webflow:flow-registry>
 
    <!-- Configures the Spring Web Flow JSF integration -->
    <faces:flow-builder-services id="flowBuilderServices" />

    <!-- A listener maintain one FacesContext instance per Web Flow request. -->
    <bean id="facesContextListener"
        class="org.springframework.faces.webflow.FlowFacesContextLifecycleListener" />

</beans>

我的流程定义:

<flow xmlns="http://www.springframework.org/schema/webflow"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.springframework.org/schema/webflow
                          http://www.springframework.org/schema/webflow/spring-webflow.xsd">
       
<var name="signService" class="sign.ServiceESign"/>       
            
<view-state id="activation" view="views/activation.xhtml" >
    <transition on="succeed" to="successState" />
    <transition on="cancel" to="failure"/>
</view-state>

<view-state id="failure" view="views/failure.xhtml" />

<view-state id="successState" view="views/success.xhtml"/>

</flow>

激活.xhtml:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC
          "-//W3C//DTD XHTML 1.0 Transitional//EN"
          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
       xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:f="http://java.sun.com/jsf/core" >
<head>
    <title>Learning Flow</title>
</head>
<body>
    <h2>Click to activate account</h2>
    <form action="${flowExecutionUrl}" >
         <input type="hidden" name="_eventId" value="succeed"/>
         <input type="submit" value="Search"/>
    </form>
    <form method="post" action="${flowExecutionUrl}">
        <input type="submit" name="_eventId_succeed"  value ="succeed"></input>
    </form>
</body>
</html>

标签: javaspringjsf-2xhtmlspring-webflow

解决方案


推荐阅读