You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pluto-scm@portals.apache.org by ms...@apache.org on 2014/12/12 06:41:14 UTC
[8/8] portals-pluto git commit: Completed support for forms with
enctype = 'application/x-www-form-urlencoded'. The hub now supports this
encoding as well as 'multipart/form-data encoding.
Completed support for forms with enctype =
'application/x-www-form-urlencoded'. The hub now supports this encoding as
well as 'multipart/form-data encoding.
Project: http://git-wip-us.apache.org/repos/asf/portals-pluto/repo
Commit: http://git-wip-us.apache.org/repos/asf/portals-pluto/commit/f63742bb
Tree: http://git-wip-us.apache.org/repos/asf/portals-pluto/tree/f63742bb
Diff: http://git-wip-us.apache.org/repos/asf/portals-pluto/diff/f63742bb
Branch: refs/heads/PortletHub
Commit: f63742bb797f974ca0a9b7446fb1c0bb401d7fe1
Parents: 3a1a3d3
Author: Scott Nicklous <ms...@apache.org>
Authored: Thu Dec 11 21:14:31 2014 +0100
Committer: Scott Nicklous <ms...@apache.org>
Committed: Thu Dec 11 21:14:31 2014 +0100
----------------------------------------------------------------------
pluto-portal/src/main/webapp/portlet.js | 36 +++++++++++++++++++--
pluto-portal/src/main/webapp/portletHubImpl.js | 12 ++++---
2 files changed, 41 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/f63742bb/pluto-portal/src/main/webapp/portlet.js
----------------------------------------------------------------------
diff --git a/pluto-portal/src/main/webapp/portlet.js b/pluto-portal/src/main/webapp/portlet.js
index 13b41d7..4b03551 100644
--- a/pluto-portal/src/main/webapp/portlet.js
+++ b/pluto-portal/src/main/webapp/portlet.js
@@ -1566,9 +1566,22 @@ var portlet = portlet || {};
* an HTML form to be submitted.
* The portlet hub will use this form to execute the action.
* <p>
+ * If the form element is specified, the encoding type must be
+ * 'application/x-www-form-urlencoded' or 'multipart/form-data'.
+ * The encoding type 'text/plain' is not supported.
+ * <p>
+ * If the encoding type is 'multipart/form-data', the submission method
+ * must be 'POST'.
+ * Form 'INPUT' elements of type 'FILE' are supported.
+ * <p>
+ * If the encoding type is 'application/x-www-form-urlencoded', the submission method
+ * can be either 'GET' or 'POST'.
+ * However, form 'INPUT' elements of type 'FILE' are not supported.
+ * <p>
* Specification of <code>element</code> is optional.
* If the <code>element</code> is not specified, the portlet hub will
- * submit the action to the server in an appropriate manner.
+ * submit the action to the server by executing a 'POST' with an action
+ * URL containing any action parameters provided.
* <p>
* A portlet action is a blocking operation.
* To allow for orderly state transitions, the portlet hub does not allow
@@ -1604,7 +1617,7 @@ var portlet = portlet || {};
* @memberOf PortletInit
*/
action : function (actParams, element) {
- var ii, arg, type, parms = null, el = null;
+ var ii, arg, type, parms = null, el = null, meth;
console.log("Executing action for portlet: " + portletId);
// check arguments. make sure there is a maximum of two
@@ -1639,13 +1652,30 @@ var portlet = portlet || {};
// if we're dealing with a form, verify method and enctype
if (el) {
- if (el.method.toUpperCase() !== 'POST' && el.method.toUpperCase() !== 'GET') {
+ meth = el.method.toUpperCase();
+
+ if (meth !== 'POST' && meth !== 'GET') {
throwIllegalArgumentException("Invalid form method " + el.method + ". Allowed methods are GET & POST ");
}
+
// allow the default, which is 'application/x-www-form-urlencoded' encoded, and also multipart/form-data
if (el.enctype && el.enctype !== 'application\/x-www-form-urlencoded' && el.enctype !== 'multipart\/form-data') {
throwIllegalArgumentException("Invalid form enctype " + el.enctype + ". Allowed: 'application\/x-www-form-urlencoded' & 'multipart\/form-data' ");
}
+
+ if (el.enctype && (el.enctype === 'multipart\/form-data') && (meth !== 'POST')) {
+ throwIllegalArgumentException("Invalid method with multipart/form-data. Must be POST.");
+ }
+
+ // if the data is supposed to be urlencoded, we don't suport FILE element
+ if (!el.enctype || (el.enctype === 'application\/x-www-form-urlencoded')) {
+ for (ii = 0; ii < el.elements.length; ii++) {
+ if (el.elements[ii].nodeName.toUpperCase() === 'INPUT'
+ && el.elements[ii].type.toUpperCase() === 'FILE') {
+ throwIllegalArgumentException("Must use enctype = 'multipart/form-data' with input type FILE.");
+ }
+ }
+ }
}
// everything ok, so do the action
http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/f63742bb/pluto-portal/src/main/webapp/portletHubImpl.js
----------------------------------------------------------------------
diff --git a/pluto-portal/src/main/webapp/portletHubImpl.js b/pluto-portal/src/main/webapp/portletHubImpl.js
index ef3fbb3..fc9dc4d 100644
--- a/pluto-portal/src/main/webapp/portletHubImpl.js
+++ b/pluto-portal/src/main/webapp/portletHubImpl.js
@@ -720,7 +720,8 @@ var portlet = portlet || {};
} else {
type = "";
}
- if (name && !el.disabled) {
+ // we don't support file type with enctype = 'application/x-www-form-urlencoded' (hub checks for this case)
+ if (name && !el.disabled && (type !== 'FILE')) {
if ((tag === 'SELECT') && (el.multiple === true)) {
// multiple select boxes need to be handled differently
for (jj = 0; jj < el.options.length; jj++) {
@@ -784,18 +785,19 @@ var portlet = portlet || {};
}
};
if (element) {
- method = element.method; // may be GET or POST
enctype = element.enctype;
if (enctype === 'multipart\/form-data') {
- // multipart/form-data is sent using FormData
+ // multipart/form-data is always POSTed using FormData
fd = new FormData(element);
console.log("ajax action: POST using FormData object: " + fd);
xhr.open(method, url, true);
xhr.send(fd);
} else {
// has to be 'application\/x-www-form-urlencoded', as the hub does not support text/plain
+ method = element.method; // may be GET or POST
fstr = encodeFormAsString(element);
- if (method.toUpperCase() === 'GET') {
+ if (!method || method.toUpperCase() === 'GET') { //default method = GET
+ // send form data as part of URL
if (url.indexOf('?') >= 0) {
url += '&' + fstr;
} else {
@@ -806,6 +808,8 @@ var portlet = portlet || {};
} else {
// has to be post, since we only support GET & POST
xhr.open(method, url, true);
+ xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
+ xhr.setRequestHeader('Content-Length', fstr.length);
xhr.send(fstr);
}
}