【问题标题】:Spring web flow, create subflow with input fieldSpring web flow,使用输入字段创建子流
【发布时间】:2012-06-06 09:18:23
【问题描述】:

我从 Spring Web Flow 开始,阅读并遵循文档。我创建了一个新流程:

test-flow.xml

<?xml version="1.0" encoding="UTF-8"?>
<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-2.0.xsd">

    <var name="testName" class="com.project.TestView" />

    <view-state id="test">
        <on-entry>
            <set name="flowScope.name" value="testName.name" />
        </on-entry>
        <transition on="test" to="saveName"/>
    </view-state>

    <subflow-state id="subTest" subflow="testSub-flow">
        <input name="nameVar" value="name" />
        <transition to="error" />
    </subflow-state>

    <view-state id="error" />
    <end-state id="finish" />   
</flow>

我正在尝试创建一个 testSub-flow.xml

<?xml version="1.0" encoding="UTF-8"?>
<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-2.0.xsd">

    <input type="String" name="nameVar" />

    <on-start>
        <evaluate expression="com.project.TestView.printSomething(nameVar)" result="flowScope.testPrint" />
    </on-start>

    <view-state id="printTest" >
        <transition on="restart" to="endSub" />
    </view-state>

    <end-state id="endSub" />

</flow>

调用的方法是:

@Transactional(readOnly = true)
    public String printSomething(String text){
        System.out.print(text + " this is a test");
        return text + " this is a test";
    }

在加载主流程时,浏览器出现异常test-flow.xml

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.webflow.execution.ActionExecutionException: Exception thrown executing [AnnotatedAction@6ca837 targetAction = [EvaluateAction@7aed3a expression = com.project.TestView.printSomething(nameVar), resultExpression = flowScope.testPrint], attributes = map[[empty]]] in state 'null' of flow 'test' -- action execution attributes were 'map[[empty]]'

可能是什么问题?提前致谢。

【问题讨论】:

  • 该表达式期望有一个 id 为 com.project.TestView 的 spring bean。是这样吗?该异常应该还有更多内容 - 一个堆栈跟踪可能会告诉您它是由 EvaluationExpression 引起的。无论您的异常处理机制是什么,该部分都可能被吞没。

标签: spring-webflow


【解决方案1】:

乍一看,它似乎找不到任何启动状态。尝试在流标签中添加 start-state 属性:

    <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-2.0.xsd" 
            start-state="test">

如果这不能解决问题,则可能是流程构建器找不到名为“saveName”的状态。问题可能出在这一行:

<transition on="test" to="saveName"/>

如果您想在“test”事件发生时调用子流程,请编写“subTest”而不是“saveName”以调用子流程。

所以,那行应该是:

<transition on="test" to="subTest"/>

另外,请注意,您没有为这些视图状态指定任何视图。

希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-10-04
    • 2013-11-02
    • 2012-08-24
    • 2013-06-18
    • 2012-06-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多