{"id":29,"date":"2008-12-08T13:51:00","date_gmt":"2008-12-08T11:51:00","guid":{"rendered":"https:\/\/blog.lifshitz.net\/adding-ajax-delayloading-indicator-using-java-stripes"},"modified":"2014-11-17T16:09:05","modified_gmt":"2014-11-17T14:09:05","slug":"adding-ajax-delayloading-indicator-using-java-stripes","status":"publish","type":"post","link":"https:\/\/blog.lifshitz.net\/?p=29","title":{"rendered":"Adding AJAX delay\/loading indicator using Java Stripes"},"content":{"rendered":"<p>While exploring the  <a href=\"http:\/\/www.stripesframework.org\/\">Stripes<\/a> framework, I spent a while looking at how to add the &#8216;spinner&#8217; indicator when your server side is processing a long request. Here&#8217;s a short summary of what I did to achieve that, hope it could help save someone a little time:<\/p>\n<p>1. Select a spinner image \ud83d\ude42 I found this cool place where you can generate an image of your choosing at <a href=\"http:\/\/www.ajaxload.info\/\">ajaxload.info<\/a>. Generate whatever you like and save it somewhere, let&#8217;s say under &#8216;images\/smallspinner.gif&#8217;.<\/p>\n<p>2. In your .jsp file add the following javascript method just before the invoke method you use (again, assuming you&#8217;re working with Stripes):<br \/><code><\/p>\n<pre><br \/>function showSpinner(container)  {<br \/>         var obj = document.getElementById(container);<br \/>         obj.innerHTML = \"&lt;div ID='spinner'&gt;<br \/>\t\t&lt;img src='images\/smallspinner.gif'\/&gt;&lt;\/div&gt;\";<br \/>}<br \/><\/pre>\n<p><\/code><br \/>then update your invoke method to call the <i>showSpinner<\/i> method at the right time:<br \/><code><\/p>\n<pre><br \/>function invoke(form, event, container) {<br \/>         if (!form.onsubmit) { <br \/>             form.onsubmit = function() { return false } <br \/>         };<br \/>        <strong> showSpinner(container); \/\/This is the new call..<\/strong><br \/>         var params = Form.serialize(form, {submit:event});<br \/>         new Ajax.Updater(container, form.action, <br \/>                 {method:'post', parameters:params});<br \/>}<br \/><\/pre>\n<p><\/code><br \/>3. Ah, that&#8217;s about it.. A short explanation: The target container&#8217;s contents is being replaced just before the call invocation with the &#8216;spinner&#8217; image, so it shows as &#8216;loading&#8217; until the call returns, and then the server side replaces it with the actual HTML result once it&#8217;s ready.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>While exploring the Stripes framework, I spent a while looking at how to add the &#8216;spinner&#8217; indicator when your server side is processing a long request. Here&#8217;s a short summary of what I did to achieve that, hope it could help save someone a little time: 1. Select a spinner image \ud83d\ude42 I found this&hellip;&nbsp;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"neve_meta_sidebar":"","neve_meta_container":"","neve_meta_enable_content_width":"","neve_meta_content_width":0,"neve_meta_title_alignment":"","neve_meta_author_avatar":"","neve_post_elements_order":"","neve_meta_disable_header":"","neve_meta_disable_footer":"","neve_meta_disable_title":"","footnotes":""},"categories":[24,20,22,23],"tags":[],"_links":{"self":[{"href":"https:\/\/blog.lifshitz.net\/index.php?rest_route=\/wp\/v2\/posts\/29"}],"collection":[{"href":"https:\/\/blog.lifshitz.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.lifshitz.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.lifshitz.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.lifshitz.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=29"}],"version-history":[{"count":0,"href":"https:\/\/blog.lifshitz.net\/index.php?rest_route=\/wp\/v2\/posts\/29\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.lifshitz.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=29"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.lifshitz.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=29"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.lifshitz.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=29"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}