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);

}

about メソッドを呼び出す flow.xml のスニペットを次に示します。

<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

LocalAttributeMapを使用できます。フローは次のようになります。

<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>

最初のコントローラーのメソッドsetAttributeは、属性マップを設定します。

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);
}

そして、他のコントローラーで属性値を取得できます。

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

よろしく。

于 2013-03-08T10:58:09.120 に答える