thanks Deepak Dixit for this improvement, end user will appreciate ;)

Nicolas

Le 03/04/2012 10:41, jler...@apache.org a écrit :
Author: jleroux
Date: Tue Apr  3 08:41:06 2012
New Revision: 1308751

URL: http://svn.apache.org/viewvc?rev=1308751&view=rev
Log:
A patch from Deepak Dixit for "Auto-completer request should be async." 
https://issues.apache.org/jira/browse/OFBIZ-4780

Currently auto-completer uses sync call to prepare auto-completer source 
(result list).
Due to this user can't perform any other operation on lookup field and user 
should have to wait until response came.
In general, synchronous requests should never be used because they tend to 
block the execution of anything else on the page (or even the entire browser 
UI), which isn't good.
Also ajax-loader image not display on google chrome browser due to sync request.

Need to use async request for auto-completer.

Modified:
     ofbiz/trunk/framework/images/webapp/images/selectall.js
     
ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/RequestHandler.java

Modified: ofbiz/trunk/framework/images/webapp/images/selectall.js
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/framework/images/webapp/images/selectall.js?rev=1308751&r1=1308750&r2=1308751&view=diff
==============================================================================
--- ofbiz/trunk/framework/images/webapp/images/selectall.js (original)
+++ ofbiz/trunk/framework/images/webapp/images/selectall.js Tue Apr  3 08:41:06 
2012
@@ -17,6 +17,9 @@
   * under the License.
   */

+//Define global variable to store last auto-completer request object (jqXHR).
+var LAST_AUTOCOMP_REF = null;
+
  // Check Box Select/Toggle Functions for Select/Toggle All

  function toggle(e) {
@@ -412,8 +415,15 @@ function ajaxAutoCompleter(areaCsvString
                  jQuery.ajax({
                      url: url,
                      type: "post",
-                    async: false,
                      data: {term : request.term},
+                    beforeSend: function (jqXHR, settings) {
+                        //If LAST_AUTOCOMP_REF is not null means an existing 
ajax auto-completer request is in progress, so need to abort them to prevent 
inconsistent behavior of autocompleter
+                        if (LAST_AUTOCOMP_REF != null) {
+                            var oldRef = LAST_AUTOCOMP_REF;
+                            oldRef.abort();
+                        }
+                        LAST_AUTOCOMP_REF= jqXHR;
+                    },
                      success: function(data) {
                        // reset the autocomp field
                        autocomp = undefined;

Modified: 
ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/RequestHandler.java
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/RequestHandler.java?rev=1308751&r1=1308750&r2=1308751&view=diff
==============================================================================
--- 
ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/RequestHandler.java 
(original)
+++ 
ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/RequestHandler.java 
Tue Apr  3 08:41:06 2012
@@ -872,7 +872,14 @@ public class RequestHandler {
          try {
              resp.flushBuffer();
          } catch (java.io.IOException e) {
-            throw new RequestHandlerException("Error flushing response 
buffer", e);
+            /*If request is an ajax request and user calls abort() method for 
on ajax request then skip throwing of RequestHandlerException .
+             Specially its done for async ajax auto completer call, if we call 
abort() method on ajax request then its showing broken pipe exception on 
console,
+             because request is aborted by client (browser).*/
+            if (!"XMLHttpRequest".equals(req.getHeader("X-Requested-With"))) {
+                throw new RequestHandlerException("Error flushing response 
buffer", e);
+            } else {
+                if (Debug.verboseOn()) Debug.logVerbose("Skip Request Handler 
Exception for ajax request.", module);
+            }
          }

          String vname = (String) req.getAttribute("_CURRENT_VIEW_");




--
Nicolas MALIN
Consultant
Tél : 06.17.66.40.06
Site projet : http://www.neogia.org/
-------
Société LibrenBerry
Tél : 02.48.02.56.12
Site : http://www.librenberry.net/

Reply via email to