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:
- Client-side handling by using JavaScript. See Double-click handling on the client-side using JavaScript.
- Server-side handling by MultiClickRequestHandler. See Configuring double-click handling.
- Both client and server side by using Struts 2.
<interceptor name="token"
class="org.apache.struts2.interceptor.TokenInterceptor"/>
<interceptor name="tokenSession"
class="org.apache.struts2.interceptor.TokenSessionStoreInterceptor"/>
Procedure
-
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 forinvalid.token(/duplicateRequest.jsp)
will be used.
-
Add the
<s:token/>
in the form, pointing to the action that has the configured token interceptor. -
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.