代码片段 / 应用笔记 · 2017年9月21日

Terminating an ExecuteAndWait action

Overview

The idea is to have 2 actions, one that execute the ExecuteAndWait action and another one that teminates the already running ExecuteAndWait action. The ExecuteAndWait action will needs to implement a Terminatable interface allowing it to be identified by the terminating action and hence be able to be informed to terminate itself through the terminate() method ( from Terminatable interface ).

XWork.xml configurations

Action longruning will be the action executing the ExecuteAndWait action where as action terminatelongrunning will be the action to terminate the _ExecuteAndWait action.

Terminatable interface

ExecuteAndWait action wish to be informed about its termination such that it could ends itself gracefully should implement this interface.

The ExecuteAndWait Action

The ExecuteAndWait action is basically a conditional loop that loop indefintely until it’s informed to ends itself by breaking the loop.

The action to terminate ExecuteAndWait action

This action terminates the ExecuteAndWait action simply informing it through the terminate() method.

The freemarker pages

status.ftl
success.ftl
terminated.ftl
termiantefailed.ftl
terminatesuccess.ftl

Special thanks to Lens that contributed this sollution in WebWork’s forum