I was able to add canceling an action by using DWR. DWR is usually used to send messages from a server to a client, but you can also use it to send a message from a client to a server.
My client side jsp for the DWR setup is as follows:
<%@ taglib prefix="s" uri="/struts-tags" %>
<%-- These files are created in the runtime --%>
<script type='text/javascript' src='/rms/dwr/util.js'></script>
<script type='text/javascript' src='/rms/dwr/interface/PushMsg.js'></script>
<script type='text/javascript' src='/rms/dwr/engine.js'></script>
<div style="color:red" id="<%= session.getId()%>"></div>
<script type="text/javascript">
dwr.engine.setActiveReverseAjax(true);
PushMsg.initMsg();
function cancelAction() {
PushMsg.cancel();
}
</script>
On the server side the PushMsg class contains the cancel method and another method the check if cancel was pressed as follows:
public void cancel(){
servletContext.setAttribute("cancel", true);
}
public Boolean isCanceled(){
return (Boolean) servletContext.getAttribute("cancel");
}
The onclick event on my cancel button calls the cancelAction() function which in turn calls the cancel method of the PushMsg class on the server.
I just poll the PushMsg class on the server by calling the iscanceled() method.
You can find information and examples on using DWR at:
http://directwebremoting.org/dwr/index.html