You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

The ExecuteAndWaitInterceptor is great for running long-lived actions in the background while showing the user a nice progress meter. This also prevents the HTTP request from timing out when the action takes more than 5 or 10 minutes.

Using this interceptor is pretty straight forward. Assuming that you are including webwork-default.xml, this interceptor is already configured but is not part of any of the default stacks. Because of the nature of this interceptor, it must be the last interceptor in the stack. A typical configuration looks like:

xwork.xml
...
<action name="myLongRunningAction" class="...">
    <interceptor-ref name="defaultStack"/>
    <interceptor-ref name="execAndWait"/>
    <result name="wait">longRunningAction-wait.jsp</result>
    <result name="success">longRunningAction-success.jsp</result>
</action>
...

This interceptor works on a per-session basis. That means that the same action name (myLongRunningAction, in the above example) cannot be run more than once at a time in a given session. On the initial request or any subsequent requests (before the action has completed), the wait result will be returned. The wait result is responsible for issuing a subsequent request back to the action, giving the effect of a self-updating progress meter.

An example of a simple wait JSP is:

longRunningAction-wait.jsp
<html>
    <head>
        <title>Please wait</title>
        <meta http-equiv="refresh" content="5;url=<ww:url includeParams="'all'" />"/>
    </head>
    <body>
        Please wait while we process your request. 
        Click <a href="<ww:url includeParams="'all'" />"></a> if this page does not reload automatically.
    </body>

Whenever the wait result is returned, the action that is currently running in the background will be placed on top of the stack. This allow you to display progress data, such as a count, in the wait page. By making the wait page automatically reload the request to the action (which will be short-circuited by the interceptor), you can give the appearance of an automatic progress meter.

  • No labels