gpt4 book ai didi

java - 动态 Action 状态问题

转载 作者:行者123 更新时间:2023-12-01 15:51:28 25 4
gpt4 key购买 nike

我在使用 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)

有人可以帮我吗?

最佳答案

to transition 的属性接受一个字符串文字。如果你想将字符串文字和EL结合起来,你需要使用模板表达式:

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

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

此外,您确定需要从服务层返回 View 状态名称吗? <action-state> 的一般模式您是否使用 <evaluate> 调用方法然后根据 <evaluate> 的结果定义不同状态的不同转换...类似于 switch 语句。看看this关于操作状态的部分。

关于java - 动态 Action 状态问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5936294/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com