user2863649
user2863649

Reputation: 15

Double click submit of a form versus submit twice

What is the difference between in terms of logical flow when we compare the events that are fired after double click on a submit button and two single clicks on it?

I have a Struts 1 application(dirtily designed) and I am not able to comprehend what is actually happening on a double click.

The JSP is like below ,Clicking on Add xItem invokes the doAdd () method of the action class (In this case str will be null in doAdd method) which forwards to xItemAdd.jsp

enter image description here

xItemAdd.jsp contains a primary form with few checkboxes and a load button.On clicking load doAdd is called where value of selected checkboxes and listbox is fetched/put in session attribute and forwards again to xItemAdd.jsp

enter image description here

xItemAdd.jsp contains scriptlets to display forms if their corresponding checkboxes are checked.So now Form1 and Form3 are displayed if 1 and 3 checkboxes were selected and Load was clicked

   <% for(int i=0;i<selmsgs.size();size++)
       {Systeml.out.println("i :"+i +"size "+selmsgs.size());
...%>

enter image description here

Here is a snippet of the action class

   Class MyAction

    {...
     public Object doAdd(.......)
       { System.out.println("Add method :");
       String[] str=request.getParameter("SelectionList");
        ArrayList<String>[] mylist=request.getParameter("CheckedValues").split(',');
         //Allowing duplicate values to be added in mylist
        if(str!=null&&str.equals("true")
          request.getSession.setAttribute("IsLoaded","false"); 
           
        if(str!=null)
        {
         request.getSession.setAttribute("ObjectList",mylist);
        request.getSession.setAttribute("IsLoaded","true"); 
        }
       return SUCCESS;   
       }
    }

With a single click on Load button in figure 2 as expected the view turns into figure 3 and if it is clicked again the forms(for selected checkboxes) are loaded and it remains as in figure 3 But in case of a double click on Load button there is a strange behavior ,each selected form is appears repeated.So Figure 3 would be like Form 1,Form3 and again Form1,Form3

After the doAdd method returns the JSP is invoked twice and the print line in the jsp as in figure 3 prints something like

i: 0 size :2

i:0 size  :1

i:1 size : 2

Appears as if two threads are executing the JSP scriplet

Can you please explain the difference in behavior between a double click on the load button here versus two simultaneous clicks on it as both would submit the form twice?

What actually happens after double click on the load button?

Upvotes: 0

Views: 2017

Answers (1)

developerwjk
developerwjk

Reputation: 8659

A double click on a submit button is two single clicks. The first will be sent off to the server to be processed silently (as in the browser will not receive the response although the server will send it) and the second will also be processed on the server but the browser will receive the response.

Buttons aren't icons. Double click doesn't make sense for them. Users should know that buttons are single click. If the users of your application don't know that, you may want to use javascript to disable the button on click before processing the submit to prevent them from trying a double click. See https://stackoverflow.com/questions/5944254/preventing-double-click-of-submit-button

Upvotes: 0

Related Questions