Double-click handlng on the client side using Struts 2

You can take full advantage of Struts 2 features to perform double-click handling for your web-based forms.

About this task

A persistent problem with Struts-based forms has been a behavior where, when the user submits a form, an accidental second click of the mouse will submit the form again. You can disable this behavior using the following steps. You can also take advantage of the Struts 2 file upload feature.

There are three ways to handle double-click scenarios in HCL Commerce:You can use the Struts 2 token interceptor to manage the multiple form submission problem. To use this feature, make sure the two token interceptors are defined in the Struts configuration file. If the configuration file is an extension of the default configuration file, you do not need to define them. The two token interceptors are defined as follows:
<interceptor name="token" 
class="org.apache.struts2.interceptor.TokenInterceptor"/>
<interceptor name="tokenSession" 
class="org.apache.struts2.interceptor.TokenSessionStoreInterceptor"/>

Procedure

  1. Add the interceptor configuration into the action that needs to manage double-click situations.
    <action class="com.ibm.commerce.struts.v2.BaseAction" 
    name="Logon">
    <param name="authenticate">0:0</param>
    <param name="csrfProtected">0:0</param>
    <param name="https">0:1</param>
    <param name="parameter">com.ibm.commerce.security.commands.LogonCmd</param>
    <interceptor-ref name="token"/>
    <!--
    <interceptor-ref name="tokenSession"></interceptor-ref>
    -->
    <result name="invalid.token">/duplicateRequest2.jsp</result>
    </action>
    Note:
    • You can use either token or tokenSession interceptor in the action.
    • If the token interceptor identifies the request as duplicate, then a result of invalid.token returns. You must have this token to add it here if you wish to return your own result. If the token is not added, a global result for invalid.token(/duplicateRequest.jsp) will be used.
  2. Add the <s:token/> in the form, pointing to the action that has the configured token interceptor.
  3. Add <%@taglib uri="struts-tags.tld" prefix="s" %> in the page that contains that form. Now, when the configured action is invoked, double-click protection is enabled and the request will not be sent more than once.