473,938 Members | 9,166 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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="enable d=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 1856
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******@veriz on.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="enabl ed=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******@veriz on.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
automaticall y 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******@veriz on.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.setAttr ibute( "idempotenc y", SAME_VALUE_EVER Y_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******@veriz on.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.goo glegroups.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
2355
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 various techniques in the past (depending on circumstances) but I'd be interested in the techniques you guys currently use. Thanks --
3
1774
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 mozilla and MSIE - is this a good way to solve the problem? Is there a better alternative? Have I done anything stupid? My aim was to disable the normal submit process then use javascript to submit which appears to bypass that and work...
6
6406
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 hidden form field. That's fair enough. My server is therefore processing a response on the first request, so what kind of HTML response should I send out on the second, duplicate,
3
2197
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 I was indeed NOT in the database), the message still comes up saying that I am in the database. what am I doing wrong? Private Sub txtEmailName_AfterUpdate() On Error GoTo Err_txtEmailName_AfterUpdate >> If DLookup("EmailName", "Contacts",...
3
3049
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 for each skill in the form. My question is how can I prevent an employee from choosing the same skill in the fields. For example I do not want the employee to be able to fill all the 15 fields with Accounting as his skillset. Once he chooses...
12
2173
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 spam. I would imagine they're using the HttpWebRequest method for this. Essentially, it would require a property on a WebForm that indicates whether it is *only* for PostBack (true by default, but configurable), which would
6
11929
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 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,
2
1391
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 jQuery’s style of calls: $('#id1').click().fadeOut('slow'). A problem I have ran into though is how to prevent a form from submitting if it fails one of the validation methods. I know how returning false to the form on submission will do the...
9
4160
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 clicked. CustomerID, StatusType are values that are manually entered by the user; StatusDate is automatically filled with the current date that the record is saved. I would like to use code behind the cmdSave button to check the table for...
0
10134
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9963
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11106
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
11288
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10657
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9857
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
8218
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6295
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4904
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.