动态动作状态问题

发布于 2024-11-06 02:30:23 字数 2367 浏览 3 评论 0原文

我在使用 Spring Webflow 时遇到问题。我的流程 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" parent="changeLang">

    <input name="hash" required="true"/>

    <action-state id="decideAction">
        <set name="flowScope.goTo" value ="verifyActionService.verifyHash(hash)" />
        <transition to="${goTo}" ></transition> 
    </action-state>

    <view-state id="correctVerify" view="registered" model="userAddressesForm">
        <transition on="addPhoneNumber" to="correctVerify">
            <evaluate expression="verifyActionService.addPhoneNumber(userAddressesForm)" />
        </transition>
        <transition on="deletePhoneNumber" to="correctVerify">
            <evaluate expression="verifyActionService.deletePhoneNumber(userAddressesForm, requestParameters.deleteNumber)" />
        </transition>
    </view-state>

    <view-state id="notCorrectVerify" view="register"></view-state>

</flow>

verifyHash 方法返回一个等于“ CorrectVerify”的状态 id,如下所示:

public String verifyHash(String hash) {
    return "correctVerify";
}

当我运行它时,出现如下错误:

at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.IllegalArgumentException: Cannot find state with id '${goTo}' in flow 'verify' -- Known state ids are 'array<String>['decideAction', 'correctVerify', 'notCorrectVerify', 'start']'
at org.springframework.webflow.engine.Flow.getStateInstance(Flow.java:348)
at org.springframework.webflow.engine.support.DefaultTargetStateResolver.resolveTargetState(DefaultTargetStateResolver.java:60)
at org.springframework.webflow.engine.Transition.execute(Transition.java:217)
at org.springframework.webflow.engine.impl.FlowExecutionImpl.execute(FlowExecutionImpl.java:391)
at org.springframework.webflow.engine.impl.RequestControlContextImpl.execute(RequestControlContextImpl.java:214)
at org.springframework.webflow.engine.TransitionableState.handleEvent(TransitionableState.java:119)

有人可以帮助我吗?

I Have problem with Spring Webflow. My flow XML definition is:

<?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" parent="changeLang">

    <input name="hash" required="true"/>

    <action-state id="decideAction">
        <set name="flowScope.goTo" value ="verifyActionService.verifyHash(hash)" />
        <transition to="${goTo}" ></transition> 
    </action-state>

    <view-state id="correctVerify" view="registered" model="userAddressesForm">
        <transition on="addPhoneNumber" to="correctVerify">
            <evaluate expression="verifyActionService.addPhoneNumber(userAddressesForm)" />
        </transition>
        <transition on="deletePhoneNumber" to="correctVerify">
            <evaluate expression="verifyActionService.deletePhoneNumber(userAddressesForm, requestParameters.deleteNumber)" />
        </transition>
    </view-state>

    <view-state id="notCorrectVerify" view="register"></view-state>

</flow>

The method verifyHash return a state id equal "correctVerify" like this:

public String verifyHash(String hash) {
    return "correctVerify";
}

When I run it, a get an error like this:

at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.IllegalArgumentException: Cannot find state with id '${goTo}' in flow 'verify' -- Known state ids are 'array<String>['decideAction', 'correctVerify', 'notCorrectVerify', 'start']'
at org.springframework.webflow.engine.Flow.getStateInstance(Flow.java:348)
at org.springframework.webflow.engine.support.DefaultTargetStateResolver.resolveTargetState(DefaultTargetStateResolver.java:60)
at org.springframework.webflow.engine.Transition.execute(Transition.java:217)
at org.springframework.webflow.engine.impl.FlowExecutionImpl.execute(FlowExecutionImpl.java:391)
at org.springframework.webflow.engine.impl.RequestControlContextImpl.execute(RequestControlContextImpl.java:214)
at org.springframework.webflow.engine.TransitionableState.handleEvent(TransitionableState.java:119)

Can anybody help me?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浪荡不羁 2024-11-13 02:30:23

transitionto 属性采用字符串文字。如果想要组合字符串文字和 EL,则需要使用模板表达式:

<transition to="#{goTo}"/>

有关两种不同类型表达式的信息可以在 文档的此部分。

另外,您确定需要从服务层返回视图状态名称吗? 的一般模式是使用 调用方法,然后根据 的结果定义到不同状态的不同转换>...类似于 switch 语句。看看这个部分关于行动状态。

The to attribute of transition takes a string literal. If you want to combine string literals and EL, you need to use a template expression:

<transition to="#{goTo}"/>

Information about the two different types of expression can be found in this section of the documentation.

Also, are you sure you need to be returning a view-state name from your service layer? The general pattern for <action-state> is you call a method using <evaluate> and then define different transitions to different states based on the result of the <evaluate>... similar to a switch statement. Take a look at this section on action states.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文