java - Spring Webflow : How to pass a bean from a controller to a flow?(使用输入映射)

标签 java spring-mvc mapping javabeans spring-webflow

我正尝试在我的一个流程中执行此操作:

<!-- Initial inputs -->
<input name="profileId" required="true" type="long" />
<input name="profile" required="true" type="com.myapp.model.Profile" />

冗余,我知道。这只是为了调试目的

这里的问题是配置文件为空 (com.myapp.model.Profile),由于所需的属性错误而向我的流处理程序抛出异常。 但是,profileId(长)不为空并且工作正常。

我的问题:

有没有可能类型不能只是一个 long 类型? (Here 是另一个相关主题)

这是我的 Controller :

@RequestMapping(value = "/mappingUrl", method = {RequestMethod.POST})
public String go2Flow(.... some parameters ...,
@ModelAttribute("profile") Profile profile,
ModelMap model) {

model.put("profile", profile);
model.put("profileId", profile.getId());

return "redirect:/app/myFlow";
}

编辑:

我解决了。由于我在我的 Spring MVC Controller 上使用 @SessionAttributes 来获取对象配置文件(名为“配置文件”),因此在我的流程中我只使用了 ExternalContext API 来检索该对象。

因此, Controller 保留了相同的代码,但在我的流程中,可以像这样使用 ExternalContext API:

<on-start>
    <evaluate expression="someService.serviceMethod(externalContext)" result="flowScope.outputVariable" />
</on-start>

然后在服务方法上:

@Override
public SomeObject serviceMethod(ExternalContext externalContext) {

     Profile profile = (Profile) externalContext.getSessionMap().get("profile");

      .....
     (method logic)
      .....
}

最佳答案

这里是你可以做的:

只保留profileId,不做必填

然后开始你的流程

<decision-state id="isProfileIdSet">
    <if test="profileId != null" then="setProfile" else="errorState" />
</decision-state>

<action-state id="setProfile">/*get Profile with id and store it in flowScope */</action-state>

<end-state id="errorState"></end-state>

并添加 <on-start>状态或<on-entry>在你的第一个状态中

关于java - Spring Webflow : How to pass a bean from a controller to a flow?(使用输入映射),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19660925/

相关文章:

java - 如何按插入时的顺序遍历所有 json 值?

java - 具有子类和所需参数的构建器设计模式?

java - 使用嵌套对象和列表反序列化 JSON。 "JSON parse error: Cannot construct"

python - 用 python 中相应的名称替换数千行 ID 名称的最佳方法是什么?

java - 键/值对 : call a method key with params , 返回用 params 构造的值

Java - 如何将频率转换为复数

java - Spring 安全上下文是否在 REST/SOAP 调用中持续存在?

java - SpringMvc Controller 类不工作

mapping - 序言中的输入

java - Zookeeper 不适用于 32 位 Windows 上安装的 JRE