13 Replies Latest reply on Sep 7, 2010 2:25 AM by Tim Evers

    How to prevent many clicks that cause continously page loading

    John Logan Newbie
      Hy!

      How to prevent many clicks that cause continously page loading in a Seam based application? It's a very annoying problem for me.
      Using RichFaces tags there is no probleam since a4j:queue, but the plain <s:link>, <h:commandLink> and <a> tags cause me many problems with this issue. I'd like to find a robust server side solution. I'd like to avoid using of javascript button disable etc...

      Thanks for sny suggestion.
        • 1. Re: How to prevent many clicks that cause continously page loading
          Leo van den berg Master

          Hi,


          I normally use a a4j:commandButton, and additionally i use a waitPanel which is basically a ModalPanel with a single animated GIF which block the screen until the action is finished.


          The Button:



          <a4j:commandButton image="/images/16/Find.png" 
                    action="#{doSomethingBean.do}"
                    eventsQueue="inputQueue" requestDelay="500" 
                    reRender="whateverPanels" 
                    onclick="#{rich:component('waitPanel')}.show();" 
                    oncomplete="#{rich:component('waitPanel')}.hide();" 
                    focus="whateverInput">
               <s:defaultAction />
          </a4j:commandButton>



          And the modal panel:




          <h:form id="waitForm" >
               <rich:modalPanel id="waitPanel" autosized="true" domElementAttachment="form" >
               <h:graphicImage value="/images/wait30.gif" />
               </rich:modalPanel>
          </h:form>
          



          Hopefully this solves your problem!



          Leo


          • 2. Re: How to prevent many clicks that cause continously page loading
            John Logan Newbie
            Thankx your answer

            I have no probleam with a4j:comandButton because of a4j:queue, but <s:link>, <h:commandLink> and <a> casue the problem. Do you have any server side solution for this issue with this tags?
            • 3. Re: How to prevent many clicks that cause continously page loading
              Leo van den berg Master

              Hi,


              My advice is to replace every button with a ajax-version, because otherwise you're NOT able to solve this without some heavyweight locking of requests at the serverside.


              Be aware that replacement is very easy, because the needed conversation parameters of s:linkl can be added with simple a4j:params and IMHO h:button shouldn't be used in your scenario.


              Leo

              • 4. Re: How to prevent many clicks that cause continously page loading
                John Logan Newbie
                In my case is too complicated to replace all non a4j buttons, because I use readied links for example for <a> tags with the full basepath + concatenated url parameters.
                • 5. Re: How to prevent many clicks that cause continously page loading
                  John Logan Newbie
                  If you try this:

                  Click rapidly many times for the left links, usernames etc.. in this site (seamframework.org)
                  Then you will get a 'bad' exception with http 400 + javax.resource.ResourceException, No Managed Connections available... :)
                  • 6. Re: How to prevent many clicks that cause continously page loading
                    Tim Evers Master

                    Use javascript to put a div (modal panel) over your entire page after a link/button is clicked. This works very well in my app. You may want to be reasonably good with javascript to get it working in every situation but it does work.

                    • 8. Re: How to prevent many clicks that cause continously page loading
                      John Logan Newbie
                      Thanks, but I really would like to find a robust server side solution! So the problem with your suggestion is that the user can disable all of the javascript on the page.

                      I think It must be a general solution for this. I know there is a <s:token> that is useable with h:form. But What what's up with <a>,<s:link>. Pherpahps Should I use a Filter, or a Jboss web server property to prevent multiple clicks with these tags???

                      The rapid many clicks that cause continously browser loading (like this site) is too bad for user experiance and performance too.

                      Thanks for any suggestion!
                      • 9. Re: How to prevent many clicks that cause continously page loading
                        Adrian Mitev Master

                        I saw a code where the HttpSession object was synchronized in a filter which guaranteed total synchronization of the request handling but i don't know how this will impact ajax and overall performance.

                        • 10. Re: How to prevent many clicks that cause continously page loading
                          Tim Evers Master

                          John Logan wrote on Sep 06, 2010 03:55:


                          Thanks, but I really would like to find a robust server side solution! So the problem with your suggestion is that the user can disable all of the javascript on the page.

                          I think It must be a general solution for this. I know there is a <s:token> that is useable with h:form. But What what's up with <a>,<s:link>. Pherpahps Should I use a Filter, or a Jboss web server property to prevent multiple clicks with these tags???

                          The rapid many clicks that cause continously browser loading (like this site) is too bad for user experiance and performance too.

                          Thanks for any suggestion!


                          Can I just make a comment on this. If you are writing an app where the user can disable javascript then the solution is to just not let them access your site if js is disabled. The fact of the matter is that your app will not work if js is disabled. From your code that I've seen so far you are using richfaces, ajax and a h:form. None of which will work without javascript enabled. Take a look at how your infrastructure works. JSF components that submit generally speaking do not just use a button type=submit to work. Thus every submit your application does is javascript. Every component that does any sort of animation is going to be javascript. Ajax is completely javascript so I think you can rule out your entire app if js is disabled.


                          So, my suggestion is forget about javascript being disabled. If it is (disabled) your entire site is broken. Either that of you need to get rid of all these technologies and write yourself some standard html from scratch where nothing uses javascript. Go back to good old servlets. :P


                          The client side solution is by far the easiest and will cover the 99.9999% of all users coming to your site. Those that try to bypass this will just end up in the situation where clicking fast multiple times gives them a undesirable outcome. Pretty sure that cost vs benefit this is really quite acceptable.

                          • 11. Re: How to prevent many clicks that cause continously page loading
                            Adrian Mitev Master

                            If the user want's to spam the client side solution want work. I can disable any script from firebug and no way for the app to detect it.

                            • 12. Re: How to prevent many clicks that cause continously page loading
                              Tim Evers Master

                              Adrian Mitev wrote on Sep 07, 2010 02:04:


                              If the user want's to spam the client side solution want work. I can disable any script from firebug and no way for the app to detect it.


                              My point exactly. If the user disables the javascript then it is their problem and any negative results suffered are outside the bounds that your application needs to worry about. You application is broken fundamentally if javascript is disabled. They wont even be able to submit the form at all if javascript is turned off so don't worry about them disabling a client side solution. Sure I could go into firebug and disable your client side solution but what will that do for me? It will allow me to spam click on a button and eventually get an error. Does it matter? Is your intended audience going to be disabling the one liner of javascript that you put in there? Will they even know how? If you run into a user that knows how to do this then the chances are they are probably smart enough to figure out that spam clicking on a link is never going to achieve their desired outcome.


                              I think you are over-complicating your solution. You have already got an application that relies on javascript for a large amount of it's functionality. So trying to solve one problem without javascript because you are worried that someone could disable it is pointless.

                              • 13. Re: How to prevent many clicks that cause continously page loading
                                Tim Evers Master

                                By the way the client side solution does work if javascript is enabled. I use it in our application and I just went and tested it and I cannot spam click. As soon as the first click happens a modal panel with please wait appears over the entire app and you can't click anything until it is done.