click-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sa...@apache.org
Subject svn commit: r780435 - /incubator/click/trunk/click/framework/src/org/apache/click/Context.java
Date Sun, 31 May 2009 14:32:53 GMT
Author: sabob
Date: Sun May 31 14:32:52 2009
New Revision: 780435

URL: http://svn.apache.org/viewvc?rev=780435&view=rev
Log:
improved Context.isAjaxRequest to return true when the request parameter "X-Requested-With"
is present. Allows IFrame to be handled as an Ajax request

Modified:
    incubator/click/trunk/click/framework/src/org/apache/click/Context.java

Modified: incubator/click/trunk/click/framework/src/org/apache/click/Context.java
URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/framework/src/org/apache/click/Context.java?rev=780435&r1=780434&r2=780435&view=diff
==============================================================================
--- incubator/click/trunk/click/framework/src/org/apache/click/Context.java (original)
+++ incubator/click/trunk/click/framework/src/org/apache/click/Context.java Sun May 31 14:32:52
2009
@@ -65,7 +65,7 @@
     /** The thread local context. */
     private static final ThreadLocal THREAD_LOCAL_CONTEXT = new ThreadLocal();
 
-    /** Ajax request header. */
+    /** Ajax request header or parameter: "<tt>X-Requested-With</tt>". */
     private static final String X_REQUESTED_WITH = "X-Requested-With";
 
     // -------------------------------------------------------------- Instance Variables
@@ -299,14 +299,22 @@
     /**
      * Return true is this is an Ajax request, false otherwise.
      * <p/>
-     * An Ajax request is identified by the presence of the request header
-     * <tt>"X-Requested-With: XMLHttpRequest"</tt>. This is the de-facto
-     * standard header used by Ajax libraries.
+     * An Ajax request is identified by the presence of the request header or
+     * request parameter: "<tt>X-Requested-With</tt>". This is the de-facto
+     * standard identifier used by Ajax libraries.
+     * <p/>
+     * <b>Note:</b> incoming requests that contains "<tt>X-Requested-With</tt>"
+     * as a request parameter will result in this method returning true. This
+     * allows one to programmatically enable Ajax requests. A common usage of
+     * this feature is when uploading files through an IFrame element. By
+     * specifying "<tt>X-Requested-With</tt>" as a request parameter the IFrame
+     * request will be handled like a normal Ajax request.
      *
      * @return true if this is an Ajax request, false otherwise
      */
     public boolean isAjaxRequest() {
-        return getRequest().getHeader(X_REQUESTED_WITH) != null;
+        return getRequest().getHeader(X_REQUESTED_WITH) != null
+            || getRequest().getParameter(X_REQUESTED_WITH) != null;
     }
 
     /**



Mime
View raw message