Author: andrei_exadel
Date: 2008-06-28 09:10:56 -0400 (Sat, 28 Jun 2008)
New Revision: 9289
Modified:
trunk/ui/fileUpload/src/main/java/org/richfaces/renderkit/FileUploadRendererBase.java
trunk/ui/fileUpload/src/main/resources/org/richfaces/renderkit/html/js/FileUpload.js
trunk/ui/fileUpload/src/main/templates/org/richfaces/fileUpload.jspx
Log:
fix problems with http session in Flesh
Modified:
trunk/ui/fileUpload/src/main/java/org/richfaces/renderkit/FileUploadRendererBase.java
===================================================================
---
trunk/ui/fileUpload/src/main/java/org/richfaces/renderkit/FileUploadRendererBase.java 2008-06-28
12:57:36 UTC (rev 9288)
+++
trunk/ui/fileUpload/src/main/java/org/richfaces/renderkit/FileUploadRendererBase.java 2008-06-28
13:10:56 UTC (rev 9289)
@@ -19,6 +19,7 @@
import javax.faces.context.ResponseWriter;
import javax.faces.render.RenderKit;
import javax.faces.render.RenderKitFactory;
+import javax.servlet.http.HttpSession;
import org.ajax4jsf.Filter;
import org.ajax4jsf.context.AjaxContext;
@@ -111,8 +112,13 @@
.get(Filter.REQUESTS_SESSIONS_BEAN_NAME);
MultipartRequest multipartRequest = map.get(uid);
-
+
clientId = clientId + ":file";
+
+ if (multipartRequest.getFileName(clientId) == null) {
+ clientId = "Filedata"; // Flesh mode
+ }
+
String fileName = multipartRequest.getFileName(clientId);
Object file = multipartRequest.getFile(clientId);
fileUpload.setLocalFileName(fileName);
@@ -660,6 +666,15 @@
}
return ((parameters.size() > 0) ? ScriptUtils.toScript(parameters) :
JSReference.NULL);
}
+
+ public String getSessionId(FacesContext context, UIComponent component) {
+ String id = null;
+ HttpSession session = (HttpSession)context.getExternalContext().getSession(false);
+ if (session != null) {
+ id = session.getId();
+ }
+ return id;
+ }
/*
* (non-Javadoc)
Modified:
trunk/ui/fileUpload/src/main/resources/org/richfaces/renderkit/html/js/FileUpload.js
===================================================================
---
trunk/ui/fileUpload/src/main/resources/org/richfaces/renderkit/html/js/FileUpload.js 2008-06-28
12:57:36 UTC (rev 9288)
+++
trunk/ui/fileUpload/src/main/resources/org/richfaces/renderkit/html/js/FileUpload.js 2008-06-28
13:10:56 UTC (rev 9289)
@@ -411,7 +411,7 @@
uploadedCount: 0,
- initialize: function(id, formId, actionUrl, stopScript, getFileSizeScript,
progressBarId, classes, label, maxFiles, events, disabled, acceptedTypes, options, labels,
parameters) {
+ initialize: function(id, formId, actionUrl, stopScript, getFileSizeScript,
progressBarId, classes, label, maxFiles, events, disabled, acceptedTypes, options, labels,
parameters, sessionId) {
this.id = id;
this.element = $(this.id);
if (formId != '') {
@@ -439,6 +439,7 @@
this.classes = classes;
this.events = events;
this.parameters = parameters;
+ this.sessionId = sessionId;
this.maxFileBatchSize = maxFiles;
this.currentInput = $(this.id + ":file");
@@ -1148,14 +1149,23 @@
this.element.fire("rich:"+eventName, object);
}
},
-
+
+ _getFleshActionUrl: function (url) {
+ if (/\?/.test(url)) {
+ var i = url.indexOf("?");
+ url = url.substring(0, i) + ";jsessionid=" + this.sessionId +
url.substring(i);
+ } else {
+ url = url + ";jsessionid=" + this.sessionId;
+ }
+ return url;
+ },
+
_flashSubmitForm: function(entry) {
entry.uid = encodeURIComponent(Math.random().toString());
-
- var action = this.actionUrl + (/\?/.test(this.actionUrl) ?
'&_richfaces_upload_uid' : '?_richfaces_upload_uid') + '=' +
encodeURI(entry.uid) + "&id=" + this.id +
"&_richfaces_upload_file_indicator=true&_richfaces_send_http_error=true";
-
- var size = this.flashComponent.uploadFile(this.uploadIndex, action);
+ var action = this._getFleshActionUrl(this.actionUrl);
+ var action = action + (/\?/.test(action) ? '&_richfaces_upload_uid=' :
'?_richfaces_upload_uid=') + encodeURI(entry.uid) + "&id=" + this.id
+
"&_richfaces_upload_file_indicator=true&_richfaces_send_http_error=true";
+ var size = this.flashComponent.uploadFile(this.uploadIndex,
action,"javax.faces.ViewState="
+this.form['javax.faces.ViewState'].value+"&"+this.form.id+"="+this.form.id);
if (this.labelMarkup) {
this.progressData = new ProgressData(size);
}
Modified: trunk/ui/fileUpload/src/main/templates/org/richfaces/fileUpload.jspx
===================================================================
--- trunk/ui/fileUpload/src/main/templates/org/richfaces/fileUpload.jspx 2008-06-28
12:57:36 UTC (rev 9288)
+++ trunk/ui/fileUpload/src/main/templates/org/richfaces/fileUpload.jspx 2008-06-28
13:10:56 UTC (rev 9289)
@@ -188,7 +188,7 @@
onadd : #{this:getAsEventHandler(context, component, "onadd")}
};
- new
FileUpload('#{clientId}','#{formId}','#{actionUrl}',#{this:getStopScript(context,
component)}, #{this:getFileSizeScript(context, component)}
,'#{this:getProgressBarId(context, component)}', FileUpload.CLASSES,
#{this:getLabelMarkup(context, component)}, #{maxCount}, events,
#{component.attributes["disabled"]}, #{this:getAcceptedTypes(context,
component)},
{'autoclear':#{component.attributes["autoclear"]},'autoUpload':#{component.attributes["immediateUpload"]},'noDuplicate':#{component.attributes["noDuplicate"]},
'allowFlash':'#{allowFlash}',
'flashComponentUrl':'#{flashComponent}'},#{this:_getLabels(labels)},#{this:getChildrenParams(context,
component)});
+ new
FileUpload('#{clientId}','#{formId}','#{actionUrl}',#{this:getStopScript(context,
component)}, #{this:getFileSizeScript(context, component)}
,'#{this:getProgressBarId(context, component)}', FileUpload.CLASSES,
#{this:getLabelMarkup(context, component)}, #{maxCount}, events,
#{component.attributes["disabled"]}, #{this:getAcceptedTypes(context,
component)},
{'autoclear':#{component.attributes["autoclear"]},'autoUpload':#{component.attributes["immediateUpload"]},'noDuplicate':#{component.attributes["noDuplicate"]},
'allowFlash':'#{allowFlash}',
'flashComponentUrl':'#{flashComponent}'},#{this:_getLabels(labels)},#{this:getChildrenParams(context,
component)},'#{this:getSessionId(context, component)}');
</script>
</span>
<f:call name="utils.encodeEndFormIfNessesary" />