Spring Web Flow整合JSF时流程Action事件未触发无法跳转如何解决
问题根因
核心是Spring Web Flow与JSF的集成配置错误、视图层组件使用不当、路径配置不匹配三类问题,具体修复方案如下:
修复步骤
1. 修正web-application-config.xml视图解析器配置
原有视图解析器仅支持.jsp后缀,与你使用的Facelets(.xhtml)不匹配,替换为适配JSF的视图解析器:
<!-- 替换原有InternalResourceViewResolver --> <bean class="org.springframework.faces.webflow.FaceletsViewResolver"> <property name="prefix" value="/WEB-INF/views/"/> <property name="suffix" value=".xhtml"/> </bean>
同时删除该配置文件中多余的普通FlowHandlerAdapter(仅保留JsfFlowHandlerAdapter即可)。
2. 修正flow-definition.xml中的适配器配置
删除文件中定义的普通Spring MVC版FlowHandlerAdapter,避免优先级覆盖适配JSF的JsfFlowHandlerAdapter:
<!-- 删除这段配置 --> <bean class="org.springframework.webflow.mvc.servlet.FlowHandlerAdapter"> <property name="flowExecutor" ref="flowExecutor" /> </bean>
3. 修正自定义流程定义的视图路径
原有view路径重复包含views/前缀,和视图解析器的prefix冲突,修改为:
<view-state id="activation" view="activation.xhtml" > <transition on="succeed" to="successState" /> <transition on="cancel" to="failure"/> </view-state> <view-state id="failure" view="failure.xhtml" /> <view-state id="successState" view="success.xhtml"/>
4. 修正activation.xhtml的表单实现
不能使用原生HTML表单,必须使用JSF标准组件才能触发Web Flow的事件处理,修改页面代码:
<?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>点击激活账户</h2> <h:form> <h:commandButton value="触发succeed事件" action="succeed"/> </h:form> </body> </html>
JSF的h:commandButton的action属性值直接对应流程定义中transition的on属性值即可,不需要手动拼接flowExecutionUrl和隐藏域,Spring Faces集成会自动处理流程上下文传递。
5. 可选web.xml补充配置(避免Facelets解析异常)
在web.xml的context-param节点下新增以下配置:
<context-param> <param-name>javax.faces.FACELETS_VIEW_MAPPINGS</param-name> <param-value>*.xhtml</param-value> </context-param> <context-param> <param-name>javax.faces.STATE_SAVING_METHOD</param-name> <param-value>server</param-value> </context-param>
内容的提问来源于stack exchange,提问作者Deathyas
相关产品推荐
相关产品推荐

