0

这是一个从 Spring 动作状态调用的片段。

public Event doSomething(){

    /* do something */

    // (1) How to create a instance of this and set custom attributes?
    AttributeMap customAttributeMap; 

    Event done = new Event(this, "done", customAttributeMap);

}

这是 flow.xml 中调用 about 方法的片段:

<action-state id="someStateId">
    <evaluate expression="flowAction.doSomething" />
    <transition on="done">
            <!-- (2) How do I access my custom attribute set in Event -->
        <evaluate expression="currentEvent.attributes.pageName" result="requestScope.pageName" />
    </transition>
</action-state>

所以,我的问题是:

  1. 如何创建具有自定义属性集的事件?
  2. 如何在 spring flow xml 文件中访问此事件的自定义属性?
4

1 回答 1

0

You can use a LocalAttributeMap. The flow would be something like this:

<action-state id="action1">
   <evaluate expression="myFirstController.setAttribute()"/>
   <transition on="done" to="action2"/>
</action-state>

<action-state id="action2">
   <evaluate expression="mySecondController.getAttribute(flowRequestContext.currentEvent.attributes)"/>
   <transition on="done" to="myView"/>
</action-state>

The method setAttribute of the first controller sets the attribute map:

public Event setAttribute() {
   Map<String,String> map = new HashMap<String,String>();
   map.put("testAttribute", "test");
   AttributeMap attributeMap = new LocalAttributeMap(map);
   return new Event(this, "done", attributeMap);
}

And then you could get the attribute value at the other controller:

public Event getAttribute(AttributeMap attributeMap) {
   String value = attributeMap.getString("testAttribute");
   ...
}

Regards.

于 2013-03-08T10:58:09.120 回答