Preventing second click

O

Oleg Konovalov

Hi,

I have a Java 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 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 association form action in Java which is totally unacceptable.

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

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,
using JDK1.4.2 and IE6.
 
?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

Oleg said:
I have a Java 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 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 association form action in Java which is totally unacceptable.

Is there any other simple solution to such problems in Java or Javascript ?
P.S.: It probably doesn't matter much, but that is a Cocoon2.0/XSLT app with
Actions in Java,
using JDK1.4.2 and IE6.

Sounds as if you need token pattern.

Arne
 
J

John

Read and enjoy!

http://javaalmanac.com/egs/javax.servlet.jsp/myformts.jsp.html


Arne Vajhøj said:
Oleg said:
I have a Java 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 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 association form action in Java which is totally unacceptable.

Is there any other simple solution to such problems in Java or Javascript
?
P.S.: It probably doesn't matter much, but that is a Cocoon2.0/XSLT app
with Actions in Java,
using JDK1.4.2 and IE6.

Sounds as if you need token pattern.

Arne
 
G

Grok

Oleg said:
I have a Java 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 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 association form action in Java which is totally unacceptable.

Is there any other simple solution to such problems in Java or Javascript ?
P.S.: It probably doesn't matter much, but that is a Cocoon2.0/XSLT app with
Actions in Java,
using JDK1.4.2 and IE6.

Sounds as if you need token pattern.

Arne

Or use a solution like ASP.Net that does that for you instead of
requiring a custom hack.
 
O

Oleg Konovalov

No, I can not use an ASP.NET, it is a Java (/Cocoon/XSLT) application.

Thank you,
Oleg.


Grok said:
Oleg said:
I have a Java 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 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 association form action in Java which is totally unacceptable.

Is there any other simple solution to such problems in Java or
Javascript ?
P.S.: It probably doesn't matter much, but that is a Cocoon2.0/XSLT app
with
Actions in Java,
using JDK1.4.2 and IE6.

Sounds as if you need token pattern.

Arne

Or use a solution like ASP.Net that does that for you instead of
requiring a custom hack.
 
G

Grok

No, I can not use an ASP.NET, it is a Java (/Cocoon/XSLT) application.

Thank you,
Oleg.

I guess I miss understood, I thought you said something about
Javascript.
 
W

Wojtek Bok

Oleg said:
Sometimes user double-clicks the button or just gets impatient and clicks
again,
which created 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 surrounded the entire form with a <div>, then placed an onSubmit="hideForm();" clause in the <form>. The code within hideForm changes the visibility
of the <div> to hidden. Basically the entire form disappears from the user's screen. I have a second <div> which starts out hidden and is made visible
at the same time the other div is being hidden. This div contains "Please wait, processing".

So the user clicks on a button, the form goes away, they get a "please wait" message, and the only buttons left are "Refresh" and "Back" in the tool bar.
 
J

John

Ask Sun, but at least it works,
Cheers!

Lew said:
(followup set to comp.lang.java.programmer)


This is essentially the token pattern that Arne recommended, with a
timestamp as a token.

What might be advantage to using a timestamp over a String or arbitrary
object as a token?

- Lew
 
L

Lew

(f-u set to comp.lang.java.programmer and comp.lang.javascript)

Wojtek said:
I surrounded the entire form with a <div>, then placed an
onSubmit="hideForm();" clause in the <form>.

An advantage of the token approach is that it is entirely server-side; it does
not rely on Javascript.

It also completely guarantees idempotency of the action.

I wonder, is it possible to double-click so fast that even Javascript might
not have time to react before the second click?

- Lew
 
W

Wojtek Bok

Lew said:
(f-u set to comp.lang.java.programmer and comp.lang.javascript)




An advantage of the token approach is that it is entirely server-side;
it does not rely on Javascript.
>
> It also completely guarantees idempotency of the action.

Well yes, I am doing that also. But using the div also gives the user something to look at, not wondering if they actually "clicked" on something.
When I hit really long reports, I will also add in a server ping to update an on-screen usage bar (based on average results from previous report runs).

This is an internal project. I can guarantee not only Javascript, but also the allowable browser versions. Anything outside the allowable software
(browser, versions, Javascript, screen resolution, media capabilities, phases of the moon :)) redirects (server side, so not dependent on anything
the browser can or cannot do) to a generic HTML error page.
I wonder, is it possible to double-click so fast that even Javascript
might not have time to react before the second click?

Well button action actually happens on the release of the mouse button. *I* cannot click fast enough to initiate two requests. The first one causes
the button to disappear, and the second one clicks on an empty space.
> idempotency

Interesting word....
 
P

PleegWat

I wonder, is it possible to double-click so fast that even Javascript might
not have time to react before the second click?

Would depend on the user agent. I think most of them handle everything
in one thread, so your second click would be processed after the
javascript for the first is done, even if the second click arrives
before it started processing the first.
BICBW
 
O

Oleg Konovalov

Wojtek,

And how/when does the form get restored to the original state ?
Any code sample ?

Thank you,
Oleg.
 
W

Wojtek Bok

top post fixed ...
> Wojtek,
>
> And how/when does the form get restored to the original state ?

When the user clicks on the button, the form onSubmit gets triggered. This runs the javascript code to hode the form and display the "Please Wait"
message. The normal submit action then happens:
- the web browser gathers the form field values
- the browser contacts the server and sends the field values
- the browser then waits for a response from the server
- when the response arrives, the web browser redraws the screen

In other words the normal cycle of a button click takes place
> Any code sample ?

http://www.google.ca/search?hl=en&q=div+hide&btnG=Google+Search
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top