Preventing second click

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

    #1

    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

    • James Black

      #3
      Re: Preventing second click

      Oleg Konovalov wrote:
      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.
      Sounds like you may want to look at using XmlHttpRequestO bject, so that
      you can query the server and let them know how much longer before the
      query is done.

      Also, rather than refreshing the screen, if the javascript maintains
      state, then when the query returns you can easily re-enable the button.

      I find it easier in situations like this to just let the javascript be
      able to maintain state.

      Comment

      • John

        #4
        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

          #5
          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

            #6
            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

              #7
              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

                #8
                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

                  #9
                  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

                    #10
                    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

                    • Wojtek Bok

                      #11
                      Re: Preventing second click

                      Lew wrote:
                      (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="hide Form();" 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.
                      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....

                      Comment

                      • PleegWat

                        #12
                        Re: Preventing second click

                        In article <lbmdnV6VONhJYK DYnZ2dnUVZ_o-dnZ2d@comcast.c om>, Lew says...
                        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

                        --
                        PleegWat
                        Remove caps to reply

                        Comment

                        • Oleg Konovalov

                          #13
                          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

                            #14
                            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...