473,385 Members | 2,274 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Preventing duplicate form submission

Hi,

I have a Java/JavaScript GUI application where I perform a lot of long DB
operations
[e.g. massive SQL Insert's], which takes 5-60 secs to perform.
Sometimes user double-clicks the button or just gets impatient and clicks
again,
which created duplicate forcm submission and hence duplicate records.
So I am trying to disable the button as soon as it is clicked, and as soon
as it's done,
re-enable it again.

I tried to do it in Javascript, just simple: <input... name=Save...
onclick="enabled=true;">
and as soon as screen refreshes, it re-enables the button automatically.
That works in some cases, however when I need to do some other Javascript
operation
(e.g. validate the fields on the screen), disabling the button automatically
stops both Javascript
and associated form action in Java which is totally unacceptable.

Is there any other simple solution to such problems in Java or Javascript ?
Maybe AJAX ?

Any help is very appreciate. Please provide a code sample or a pointer to
the resources.

Thank you in advance,
Oleg.
P.S.: It probably doesn't matter much, but that is a Cocoon2.0/XSLT app
with Actions in Java [servlet based], using JDK1.4.2 and IE6.
Oct 31 '06 #1
8 1833
Oleg Konovalov wrote:
.....
Search the cljp news group with 'token pattern'.

Oct 31 '06 #2
On Tue, 31 Oct 2006 04:31:26 GMT, "Oleg Konovalov"
<ok******@verizon.netwrote:
>Hi,

I have a Java/JavaScript GUI application where I perform a lot of long DB
operations
[e.g. massive SQL Insert's], which takes 5-60 secs to perform.
Sometimes user double-clicks the button or just gets impatient and clicks
again,
which created duplicate forcm submission and hence duplicate records.
So I am trying to disable the button as soon as it is clicked, and as soon
as it's done,
re-enable it again.

I tried to do it in Javascript, just simple: <input... name=Save...
onclick="enabled=true;">
and as soon as screen refreshes, it re-enables the button automatically.
That works in some cases, however when I need to do some other Javascript
operation
(e.g. validate the fields on the screen), disabling the button automatically
stops both Javascript
and associated form action in Java which is totally unacceptable.

Is there any other simple solution to such problems in Java or Javascript ?
Maybe AJAX ?

Any help is very appreciate. Please provide a code sample or a pointer to
the resources.

Thank you in advance,
Oleg.
P.S.: It probably doesn't matter much, but that is a Cocoon2.0/XSLT app
with Actions in Java [servlet based], using JDK1.4.2 and IE6.
If you're able to submit multiple, duplicate records, the database
most likely does not have proper constraints set up. Good software
design practices do not rely on the GUI to prevent multiple
submissions.
Oct 31 '06 #3
Oleg Konovalov <ok******@verizon.netwrote:
>I have a Java/JavaScript GUI application where I perform a lot of long DB
operations
[e.g. massive SQL Insert's], which takes 5-60 secs to perform.
Don't do these synchronously. It's just mean to users, and a bad design. You
should use a background thread to do the inserts, and have a status page that
auto-refreshes (or uses AJAX if you're fancy) until the operation is complete.
>Sometimes user double-clicks the button or just gets impatient and clicks
again, which created duplicate forcm submission and hence duplicate records.
Make your call idempotent. Include on the form a unique identifier (cf
java.util.UUID) that gets submitted along with the data, and the server
can simply ignore duplicate submissions.
>So I am trying to disable the button as soon as it is clicked, and as soon
as it's done, re-enable it again.
Good. This is a nice backup to the above. But if you do it right, you
never need to re-enable it explicitly. The form submission disables it, and
the results page doesn't have the button on it. When the user wants to make
a new submission, they go to the submission page, where it's enabled because
it's a new load of the page.
>and as soon as screen refreshes, it re-enables the button automatically.
So don't do that. Don't refresh the page, go to a results page instead.
>That works in some cases, however when I need to do some other Javascript
operation (e.g. validate the fields on the screen), disabling the button
automatically stops both Javascript and associated form action in Java
which is totally unacceptable.
What? I don't understand this requirement. If you're showing the user a
form, it is because you want them to submit it. If you don't want them to
submit it, don't show the form. Showing a form that you can validate but not
submit is lunacy.
>Is there any other simple solution to such problems in Java or Javascript ?
Maybe AJAX ?
Design your app rationally. There's no technological pixie dust that fixes a
bad design.
--
Mark Rafn da***@dagon.net <http://www.dagon.net/>
Oct 31 '06 #4
Gray Matter wrote:
On Tue, 31 Oct 2006 04:31:26 GMT, "Oleg Konovalov"
<ok******@verizon.netwrote:
>I have a Java/JavaScript GUI application where I perform a lot of long DB
operations
[e.g. massive SQL Insert's], which takes 5-60 secs to perform.
Sometimes user double-clicks the button or just gets impatient and clicks
again,
which created duplicate forcm submission and hence duplicate records.
So I am trying to disable the button as soon as it is clicked, and as soon
as it's done,
re-enable it again.
If you're able to submit multiple, duplicate records, the database
most likely does not have proper constraints set up. Good software
design practices do not rely on the GUI to prevent multiple
submissions.
Not necesarrily.

Maybe not even likely.

Only INSERT where the business rules guarantee a field
mapped to user input to be unique should fall in that
category.

Arne
Nov 1 '06 #5
Lew

Mark Rafn wrote:
Make your call idempotent. Include on the form a unique identifier (cf
java.util.UUID) that gets submitted along with the data, and the server
can simply ignore duplicate submissions.
I have seen variations on the token pattern in Web forms -

- The cited approach - a hidden field that keys the transaction. Presumably
the key is matched to a session token that is kept until the transaction
completes.

- A session token that is generated on page load and removed from the session
upon first submit; absent the token the transaction request is ignored. This
does not require unique token values.
session.setAttribute( "idempotency", SAME_VALUE_EVERY_TIME );

It surprised me when I first read of this pattern that the writer espoused the
latter variant.

I wonder of the advantages, disadvantages and gotchas of each approach.

IMHO:
- The second seems slightly more elegant, and idioms of void appeal to me
anyway. (Checking for absence, rather than checking for presence.) Checkng
for absence is slightly simpler than checking for equality.

- Second one has slightly less work to do, without UUIDs.

- First one might be more extendible in the security aspect.

/Lew
Nov 1 '06 #6
"Oleg Konovalov" <ok******@verizon.netwrites:
I have a Java/JavaScript GUI application where I perform a lot of
long DB operations [e.g. massive SQL Insert's], which takes 5-60
secs to perform.
Look into optimizing that using JDBC batches.

As another poster suggested, return to the user immediately after
setting up the job in a different thread. However, since you're really
not supposed to fire off threads in app-server containers - even
servlet containers - it would be better to deliver the "job" to a JMS
queue and have some other app read from it and do the actual database
work.

Some open-source products to help you get there:

ActiveMQ for the JMS bit:

http://www.activemq.org/site/home.html

Or take the plunge into using the MULE ESB container if you want to
automate as much as possible of the work:

http://mule.mulesource.org/wiki/display/MULE/Home
Nov 1 '06 #7
Any Javascript or Ajax solutions ?
"hiwa" <HG******@nifty.ne.jpwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
Oleg Konovalov wrote:
>.....
Search the cljp news group with 'token pattern'.


Nov 4 '06 #8
Lew
(f-u set to clj.programmer)

Oleg Konovalov wrote:
Hi,

I have a Java/JavaScript GUI application where I perform a lot of long DB
operations
[e.g. massive SQL Insert's], which takes 5-60 secs to perform.
Sometimes user double-clicks the button or just gets impatient and clicks
again,
which created duplicate forcm submission and hence duplicate records.
So I am trying to disable the button as soon as it is clicked, and as soon
as it's done,
re-enable it again.
Trying to disable a browser control (back button, refresh) from the server is
wrong and fraught with difficulty.

Make your transactions idempotent and stop trying to screw up people's browsers.

Another poster already referred you to the Token pattern. It is a solution.

- Lew
Dec 5 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: CJM | last post by:
How do people go about preventing the user from submitting a form for a 2nd time? For example, the user submits a form, clicks on the back button, and the submits the form again. I have used...
3
by: shortbackandsides.no | last post by:
I've been having trouble preventing users pressing Enter part way down a form so the incomplete form gets submitted. I came up with a possible solution - the code below seems to work in both...
6
by: nick4soup | last post by:
I have read the CGI FAQ 'How can I avoid users hitting "submit" twice' (on http://www.htmlhelp.org/faq/cgifaq.3.html#19 ) which essentially says you have to detect it at the server, using a...
3
by: ColinWard | last post by:
I am using the following code to validate that the person that is being entered into the database does not already exist. However wnem I test it by entering myself as a contact(I first checked that...
3
by: humblemally | last post by:
Goodmorning all - I created a form where you enter employee skillsets. There are about 15 different skills and the employees choose the skills they have from the list. I have created a field...
12
by: Mark Rae | last post by:
Hi, See the previous thread Request.Form abuse in this newsgroup... I'm looking for a simple and efficient way to prevent people hijacking the <formtags on my websites and using them to send...
6
by: Oleg Konovalov | last post by:
Hi, I have a Java/JavaScript GUI application where I perform a lot of long DB operations , which takes 5-60 secs to perform. Sometimes user double-clicks the button or just gets impatient and...
2
by: dwmartin18 | last post by:
I got it into my head the other day to develop my own little form validation library. More than anything I just wanted to try out of few things I’ve never done before like chainable methods -- think...
9
by: rjshrader | last post by:
I have a table (tblStatus) with three fields (CustomerID, StatusType and StatusDate). I use an unbound form with three text boxes to enter data into the table when a command button (cmdSave) is...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.