On Tue, Nov 18, 2008 at 8:31 AM, Jean-Baptiste BRIAUD -- Novlog <
[EMAIL PROTECTED]> wrote:

>
> On 18 Nov 2008, at 14:23, Derrell Lipman wrote:
>
> On Tue, Nov 18, 2008 at 8:14 AM, thron7 <[EMAIL PROTECTED]>wrote:
>
>>
>> >> Using setParameter() specifically tells it to encode the parameters in
>> the
>> >> URL.  I believe you're looking for setFormField().
>> >>
>> > If you have form fields, then a different transport will be used.
>>
>> This is true, but I strongly object against the XmlHttp transport being
>> restricted to GET and URL parameters. If this is really the case,
>> somebody has to open up a bug for it. XmlHttp transport has to support
>> POST and setParameters() working on the request body!
>
>
> XmlHttp transport _does_ support POST.  That's not the issue.  The issue
> which has been discussed in depth in the past is that even with POST, it
> must be possible to add parameters to the URL.  You (and the reset of those
> in this discussion) are right that there *should* be a way to add parameters
> to the POST request body.  There's just no way to explicitly specify that
> currently.   This is just one of many issues that have been addressed in the
> past, that should be addressed in a rewrite of qx.io.remote.*
>
> I didn't know it was discussed before, sorry ...So, I do agree with you :
> parameter to the POST request body is a need.
>

Jean-Baptiste, would you please test the attached patch (or pull from SVN;
I've checked it in).  Note the new parameter available to setParameter()
which specifies whether you want the parameter to be in the URL or as data.
This should do exactly what you're looking for.  Let me know whether this
works properly for you.

Cheers,

Derrell
diff --git a/qooxdoo/framework/source/class/qx/io/remote/Request.js b/qooxdoo/framework/source/class/qx/io/remote/Request.js
index 8191db7..edb9f78 100644
--- a/qooxdoo/framework/source/class/qx/io/remote/Request.js
+++ b/qooxdoo/framework/source/class/qx/io/remote/Request.js
@@ -51,7 +51,8 @@ qx.Class.define("qx.io.remote.Request",
     this.base(arguments);
 
     this.__requestHeaders = {};
-    this.__parameters = {};
+    this.__urlParameters = {};
+    this.__dataParameters = {};
     this.__formFields = {};
 
     if (vUrl !== undefined) {
@@ -335,7 +336,8 @@ qx.Class.define("qx.io.remote.Request",
   {
 
     __requestHeaders : null,
-    __parameters : null,
+    __urlParameters : null,
+    __dataParameters : null,
     __formFields : null,
     __seqNum : null,
 
@@ -791,48 +793,110 @@ qx.Class.define("qx.io.remote.Request",
     /**
      * Add a parameter to the request.
      *
-     * @param vId {String} String identifier of the parameter to add.
-     * @param vValue {var} Value of parameter. May be a string (for one parameter) or an array of
-     *     strings (for setting multiple parameter values with the same parameter
-     *     name).
+     * @param vId {String}
+     *   String identifier of the parameter to add.
+     *
+     * @param vValue {var}
+     *   Value of parameter. May be a string (for one parameter) or an array
+     *   of strings (for setting multiple parameter values with the same
+     *   parameter name).
+     *
+     * @param bAsData {Boolean | false}
+     *   If <i>false</i>, add the parameter to the URL.  If <i>true</i> then
+     *   instead the parameters added by calls to this method will be combined
+     *   into a string added as the request data, as if the entire set of
+     *   parameters had been pre-build and passed to setData().
+     *
+     * Note: Parameters requested to be sent as data will be silently dropped
+     *       if data is manually added via a call to setData().
+     *
+     * Note: Some transports, e.g. Script, do not support passing parameters
+     *       as data.
+     *
      * @return {void}
      */
-    setParameter : function(vId, vValue) {
-      this.__parameters[vId] = vValue;
+    setParameter : function(vId, vValue, bAsData)
+    {
+      if (bAsData)
+      {
+        this.__dataParameters[vId] = vValue;
+      }
+      else
+      {
+        this.__urlParameters[vId] = vValue;
+      }
     },
 
 
     /**
      * Remove a parameter from the request.
      *
-     * @param vId {String} Identifier of the parameter to remove.
+     * @param vId {String}
+     *   Identifier of the parameter to remove.
+     *
+     * @param bFromData {Boolean}
+     *   If <i>false</i> then remove the parameter of the URL parameter list.
+     *   If <i>true</i> then remove it from the list of parameters to be sent
+     *   as request data.
+     *
      * @return {void}
      */
-    removeParameter : function(vId) {
-      delete this.__parameters[vId];
+    removeParameter : function(vId, bFromData)
+    {
+      if (bFromData)
+      {
+        delete this.__dataParameters[vId];
+      }
+      else
+      {
+        delete this.__urlParameters[vId];
+      }
     },
 
 
     /**
      * Get a parameter in the request.
      *
-     * @param vId {String} Identifier of the parameter to get.
-     * @return {var} TODOC
+     * @param vId {String}
+     *   Identifier of the parameter to get.
+     *
+     * @param bFromData {Boolean}
+     *   If <i>false</i> then retrieve the parameter from the URL parameter
+     *   list. If <i>true</i> then retrieve it from the list of parameters to
+     *   be sent as request data.
+     *
+     * @return {var}
+     *   The requested parameter value
+     *
      */
-    getParameter : function(vId) {
-      return this.__parameters[vId] || null;
+    getParameter : function(vId, bFromData)
+    {
+      if (bFromData)
+      {
+        return this.__dataParameters[vId] || null;
+      }
+      else
+      {
+        return this.__urlParameters[vId] || null;
+      }
     },
 
 
     /**
      * Returns the object containg all parameters for the request.
      *
-     * @return {Object} The returned object has as its property names each of the ids of
-     *     parameters which have been added, and as each property value, the value
-     *     of the property corresponding to that id.
+     * @param bFromData {Boolean}
+     *   If <i>false</i> then retrieve the URL parameter list.
+     *   If <i>true</i> then retrieve the data parameter list.
+     *
+     * @return {Object}
+     *   The returned object has as its property names each of the ids of
+     *   parameters which have been added, and as each property value, the
+     *   value of the property corresponding to that id.
      */
-    getParameters : function() {
-      return this.__parameters;
+    getParameters : function(bFromData)
+    {
+      return (bFromData ? this.__dataParameters : this.__urlParameters);
     },
 
 
@@ -919,6 +983,8 @@ qx.Class.define("qx.io.remote.Request",
   destruct : function()
   {
     this.setTransport(null);
-    this._disposeFields("__requestHeaders", "__parameters", "__formFields");
+    this._disposeFields("__requestHeaders",
+                        "__urlParameters",
+                        "__formFields");
   }
 });
diff --git a/qooxdoo/framework/source/class/qx/io/remote/transport/Iframe.js b/qooxdoo/framework/source/class/qx/io/remote/transport/Iframe.js
index be167d7..7fa5c39 100644
--- a/qooxdoo/framework/source/class/qx/io/remote/transport/Iframe.js
+++ b/qooxdoo/framework/source/class/qx/io/remote/transport/Iframe.js
@@ -174,7 +174,7 @@ qx.Class.define("qx.io.remote.transport.Iframe",
       // --------------------------------------
       //   Adding parameters
       // --------------------------------------
-      var vParameters = this.getParameters();
+      var vParameters = this.getParameters(false);
       var vParametersList = [];
 
       for (var vId in vParameters)
@@ -197,6 +197,41 @@ qx.Class.define("qx.io.remote.transport.Iframe",
         vUrl += (vUrl.indexOf("?") >= 0 ? "&" : "?") + vParametersList.join("&");
       }
 
+      // --------------------------------------------------------
+      //   Adding data parameters (if no data is already present)
+      // --------------------------------------------------------
+      if (this.getData() === null)
+      {
+        var vParameters = this.getParameters(true);
+        var vParametersList = [];
+
+        for (var vId in vParameters)
+        {
+          var value = vParameters[vId];
+
+          if (value instanceof Array)
+          {
+            for (var i=0; i<value.length; i++)
+            {
+              vParametersList.push(encodeURIComponent(vId) +
+                                   "=" +
+                                   encodeURIComponent(value[i]));
+            }
+          }
+          else
+          {
+            vParametersList.push(encodeURIComponent(vId) +
+                                 "=" +
+                                 encodeURIComponent(value));
+          }
+        }
+
+        if (vParametersList.length > 0)
+        {
+          this.setData(vParametersList.join("&"));
+        }
+      }
+
       // --------------------------------------
       //   Adding form fields
       // --------------------------------------
diff --git a/qooxdoo/framework/source/class/qx/io/remote/transport/XmlHttp.js b/qooxdoo/framework/source/class/qx/io/remote/transport/XmlHttp.js
index ff45b71..f8dffd3 100644
--- a/qooxdoo/framework/source/class/qx/io/remote/transport/XmlHttp.js
+++ b/qooxdoo/framework/source/class/qx/io/remote/transport/XmlHttp.js
@@ -181,9 +181,9 @@ qx.Class.define("qx.io.remote.transport.XmlHttp",
       this.__localRequest = vLocalRequest;
 
       // --------------------------------------
-      //   Adding parameters
+      //   Adding URL parameters
       // --------------------------------------
-      var vParameters = this.getParameters();
+      var vParameters = this.getParameters(false);
       var vParametersList = [];
 
       for (var vId in vParameters)
@@ -206,6 +206,41 @@ qx.Class.define("qx.io.remote.transport.XmlHttp",
         vUrl += (vUrl.indexOf("?") >= 0 ? "&" : "?") + vParametersList.join("&");
       }
 
+      // --------------------------------------------------------
+      //   Adding data parameters (if no data is already present)
+      // --------------------------------------------------------
+      if (this.getData() === null)
+      {
+        var vParameters = this.getParameters(true);
+        var vParametersList = [];
+
+        for (var vId in vParameters)
+        {
+          var value = vParameters[vId];
+
+          if (value instanceof Array)
+          {
+            for (var i=0; i<value.length; i++)
+            {
+              vParametersList.push(encodeURIComponent(vId) +
+                                   "=" +
+                                   encodeURIComponent(value[i]));
+            }
+          }
+          else
+          {
+            vParametersList.push(encodeURIComponent(vId) +
+                                 "=" +
+                                 encodeURIComponent(value));
+          }
+        }
+
+        if (vParametersList.length > 0)
+        {
+          this.setData(vParametersList.join("&"));
+        }
+      }
+
       var encode64 = function(input)
       {
         var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
qooxdoo-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel

Reply via email to