0

我将以一种操作状态将我的实体 ID 保存到会话中:

<on-exit>
<evaluate expression="persistantService.saveOrUpdate(flowScope.entity)"/>
<evaluate expression="externalContext.sessionMap.put('entityId', flowScope.entity.Id)"/>
</on-exit>

实际上,entity.Id 字段 - 是 int。

在流程开始时,我试图从会话中获取 entityId,如果存在,则从存储中加载它,否则 - 创建新的。这里我想怎么做:

<decision-state id="test">
<if test="externalContext.sessionMap.contains('entityId')"
then="findExistingEntity"
else="creteNewEntity"/>
</decision-state>

<action-state id="findExistingEntity">
<evaluate expression="persistantService.findEntityById(externalContext.sessionMap.entityId)" 
result="flowScope.entity" />
</action-state>

问题是persistantService.findEntityById 接受int,但不接受从会话中获取的Object 或Integer。我该如何解决?如何将 externalContext.sessionMap.entityId 转换为 int?或者可能还有另一种方法来测试该实体是否已保存并从持久存储中加载它?

4

1 回答 1

0

我会使用对话范围

<on-exit>
    <evaluate expression="persistantService.saveOrUpdate(flowScope.entity)"/>
    <set name="conversationScope.entityId" value="flowScope.entity.Id"/>
</on-exit>

...

<decision-state id="test">
    <if test="conversationScope.entityId != null"  
    <!-- i'm not sure if that works you might put the test in a method in a bean and call that--!>
        then="findExistingEntity"
        else="creteNewEntity"/>
</decision-state>

<action-state id="findExistingEntity">
    <evaluate expression="persistantService.findEntityById(conversationScope.entityId)" 
        result="flowScope.entity" />
</action-state>
于 2013-04-29T13:44:17.343 回答