Preventing second click

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Oleg Konovalov

    Preventing second click

    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="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 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.


  • Arne Vajhøj

    #2
    Re: Preventing second click

    Oleg Konovalov wrote:
    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="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 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

    Comment

    • John

      #3
      Re: Preventing second click

      Read and enjoy!




      "Arne Vajhøj" <arne@vajhoej.d kwrote in message
      news:M2B_g.2270 8$2g4.5720@duke read09...
      Oleg Konovalov wrote:
      >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="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
      >automaticall y 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

      Comment

      • Lew

        #4
        Re: Preventing second click

        (followup set to comp.lang.java. programmer)

        John wrote: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

        Comment

        • Grok

          #5
          Re: Preventing second click

          On Sat, 21 Oct 2006 22:53:32 -0400, Arne Vajhøj <arne@vajhoej.d k>
          wrote:
          >Oleg Konovalov wrote:
          >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="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
          >automaticall y 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.

          Comment

          • Oleg Konovalov

            #6
            Re: Preventing second click

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

            Thank you,
            Oleg.


            "Grok" <grok@pregmail. comwrote in message
            news:5ranj2dh3g bv6muihkndmp8k5 dg5cajpbu@4ax.c om...
            On Sat, 21 Oct 2006 22:53:32 -0400, Arne Vajhøj <arne@vajhoej.d k>
            wrote:
            >
            >>Oleg Konovalov wrote:
            >>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="enab led=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
            >>automatical ly 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.

            Comment

            • Grok

              #7
              Re: Preventing second click

              On Mon, 23 Oct 2006 02:10:23 GMT, "Oleg Konovalov"
              <okonoval@veriz on.netwrote:
              >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.

              Comment

              • Wojtek Bok

                #8
                Re: Preventing second click

                Oleg Konovalov wrote:
                Hi,
                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="hideF orm();" clause in the <form>. The code within hideForm changes the visibility
                of the <divto hidden. Basically the entire form disappears from the user's screen. I have a second <divwhich 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.

                Comment

                • Lew

                  #9
                  Re: Preventing second click

                  (f-u set to comp.lang.java. programmer and comp.lang.javas cript)
                  Oleg Konovalov wrote:
                  >Hi,
                  >
                  >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.
                  Wojtek Bok wrote:
                  I surrounded the entire form with a <div>, then placed an
                  onSubmit="hideF orm();" 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

                  Comment

                  • Oleg Konovalov

                    #10
                    Re: Preventing second click

                    Wojtek,

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

                    Thank you,
                    Oleg.


                    "Wojtek Bok" <wb@nospam.comw rote in message
                    news:a24%g.2996 2$P7.21237@edtn ps90...
                    Oleg Konovalov wrote:
                    >Hi,
                    >
                    >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="hideF orm();" clause in the <form>. The code within hideForm
                    changes the visibility of the <divto hidden. Basically the entire form
                    disappears from the user's screen. I have a second <divwhich 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.

                    Comment

                    • Wojtek Bok

                      #11
                      Re: Preventing second click

                      Oleg Konovalov wrote:
                      "Wojtek Bok" <wb@nospam.comw rote in message
                      news:a24%g.2996 2$P7.21237@edtn ps90...
                      >Oleg Konovalov wrote:
                      >>Hi,
                      >>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="hide Form();" clause in the <form>. The code within hideForm
                      >changes the visibility of the <divto hidden. Basically the entire form
                      >disappears from the user's screen. I have a second <divwhich 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.
                      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 ?

                      Comment

                      Working...