Author: andrei_exadel
Date: 2008-02-25 12:57:31 -0500 (Mon, 25 Feb 2008)
New Revision: 6332
Modified:
trunk/sandbox/ui/fileUpload/src/main/config/component/fileUpload.xml
trunk/sandbox/ui/fileUpload/src/main/java/org/richfaces/org/jboss/seam/ui/component/UIFileUpload.java
trunk/sandbox/ui/fileUpload/src/main/java/org/richfaces/org/jboss/seam/ui/renderkit/FileUploadRendererBase.java
trunk/sandbox/ui/fileUpload/src/main/java/org/richfaces/org/jboss/seam/web/MultipartFilter.java
trunk/sandbox/ui/fileUpload/src/main/java/org/richfaces/org/jboss/seam/web/MultipartRequest.java
trunk/sandbox/ui/fileUpload/src/main/resources/org/richfaces/renderkit/html/js/FileUpload.js
trunk/sandbox/ui/fileUpload/src/main/templates/org/richfaces/fileUpload.jspx
Log:
associate progress percent with file entry uid in session scope; implement autoclear
functionality; fix bugs
Modified: trunk/sandbox/ui/fileUpload/src/main/config/component/fileUpload.xml
===================================================================
--- trunk/sandbox/ui/fileUpload/src/main/config/component/fileUpload.xml 2008-02-25
17:55:46 UTC (rev 6331)
+++ trunk/sandbox/ui/fileUpload/src/main/config/component/fileUpload.xml 2008-02-25
17:57:31 UTC (rev 6332)
@@ -204,6 +204,14 @@
<defaultvalue>false</defaultvalue>
</property>
<property>
+ <name>autoclear</name>
+ <classname>boolean</classname>
+ <description>
+ If this attribute is true files will be immediatelly removed from list after upload
completed
+ </description>
+ <defaultvalue>false</defaultvalue>
+ </property>
+ <property>
<name>acceptedTypes</name>
<classname>java.lang.String</classname>
<description>
Modified:
trunk/sandbox/ui/fileUpload/src/main/java/org/richfaces/org/jboss/seam/ui/component/UIFileUpload.java
===================================================================
---
trunk/sandbox/ui/fileUpload/src/main/java/org/richfaces/org/jboss/seam/ui/component/UIFileUpload.java 2008-02-25
17:55:46 UTC (rev 6331)
+++
trunk/sandbox/ui/fileUpload/src/main/java/org/richfaces/org/jboss/seam/ui/component/UIFileUpload.java 2008-02-25
17:57:31 UTC (rev 6332)
@@ -4,6 +4,8 @@
import java.util.Map;
import javax.el.MethodExpression;
+import javax.el.ValueExpression;
+import javax.faces.component.UIComponent;
import javax.faces.component.UIInput;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
@@ -14,6 +16,7 @@
import org.ajax4jsf.context.AjaxContextImpl;
import org.richfaces.event.FileUploadListener;
import org.richfaces.event.UploadEvent;
+import org.richfaces.org.jboss.seam.ui.renderkit.FileUploadRendererBase;
import org.richfaces.org.jboss.seam.web.MultipartFilter;
import org.richfaces.org.jboss.seam.web.MultipartRequest;
@@ -44,7 +47,19 @@
private Integer localFileSize;
private InputStream localInputStream;
+
+ private void setupProgressBarValueExpression(FacesContext context, String uid) {
+ FileUploadRendererBase renderer =
(FileUploadRendererBase)this.getRenderer(context);
+ UIComponent progressBar = renderer.getProgressBar(context, this);
+ String exprStr = "#{" + MultipartFilter.PERCENT_BEAN_NAME +
"['"+uid+"']}";
+ ValueExpression ex = context.getApplication().getExpressionFactory()
+ .createValueExpression(context.getELContext(), exprStr,
+ Integer.class);
+ progressBar.setValueExpression("value", ex);
+ }
+
+
// @Override
// public void processUpdates(FacesContext context) {
// ValueExpression dataBinding = getValueExpression("data");
@@ -186,6 +201,7 @@
if (sessions != null) {
MultipartRequest multipartRequest = sessions.get(uid);
if (multipartRequest != null) {
+ setupProgressBarValueExpression(facesContext, uid);
ajaxContext.setResponseData(multipartRequest.getSize());
}
}
Modified:
trunk/sandbox/ui/fileUpload/src/main/java/org/richfaces/org/jboss/seam/ui/renderkit/FileUploadRendererBase.java
===================================================================
---
trunk/sandbox/ui/fileUpload/src/main/java/org/richfaces/org/jboss/seam/ui/renderkit/FileUploadRendererBase.java 2008-02-25
17:55:46 UTC (rev 6331)
+++
trunk/sandbox/ui/fileUpload/src/main/java/org/richfaces/org/jboss/seam/ui/renderkit/FileUploadRendererBase.java 2008-02-25
17:57:31 UTC (rev 6332)
@@ -344,7 +344,7 @@
* @param component
* @return
*/
- private UIComponent getProgressBar(FacesContext context,
+ public UIComponent getProgressBar(FacesContext context,
UIComponent component) {
UIComponent progressBar = component.getFacet("progress");
if (null == progressBar) {
@@ -352,11 +352,11 @@
}
//We associate progress bar's percent value in session scope with file upload
component id
- String exprStr = "#{" + MultipartFilter.PERCENT_BEAN_NAME +
"['"+component.getClientId(context)+"']}";
- ValueExpression ex = context.getApplication().getExpressionFactory()
- .createValueExpression(context.getELContext(), exprStr,
- Integer.class);
- progressBar.setValueExpression("value", ex);
+// String exprStr = "#{" + MultipartFilter.PERCENT_BEAN_NAME +
"['"+component.getClientId(context)+"']}";
+// ValueExpression ex = context.getApplication().getExpressionFactory()
+// .createValueExpression(context.getELContext(), exprStr,
+// Integer.class);
+ //progressBar.getAttributes().put("value", 0);
progressBar.getAttributes().put("minValue", -1);
progressBar.getAttributes().put("enabled", false);
progressBar.setTransient(false);
Modified:
trunk/sandbox/ui/fileUpload/src/main/java/org/richfaces/org/jboss/seam/web/MultipartFilter.java
===================================================================
---
trunk/sandbox/ui/fileUpload/src/main/java/org/richfaces/org/jboss/seam/web/MultipartFilter.java 2008-02-25
17:55:46 UTC (rev 6331)
+++
trunk/sandbox/ui/fileUpload/src/main/java/org/richfaces/org/jboss/seam/web/MultipartFilter.java 2008-02-25
17:57:31 UTC (rev 6332)
@@ -75,10 +75,10 @@
HttpServletRequest httpRequest = (HttpServletRequest) request;
String uid = httpRequest.getParameter("uid");
- String componentId = httpRequest.getParameter("clientId");
+ //String componentId = httpRequest.getParameter("clientId");
if (isMultipartRequest(httpRequest)) {
MultipartRequest multipartRequest = new MultipartRequest(
- httpRequest, createTempFiles, maxRequestSize, componentId);
+ httpRequest, createTempFiles, maxRequestSize, uid);
Map<String, MultipartRequest> sessionsMap = null;
Map<String, Object> percentMap = null;
@@ -100,7 +100,7 @@
}
}
- percentMap.put(componentId, 0); // associate percent value with file upload
component ID
+ percentMap.put(uid, 0); // associate percent value with file entry uid
sessionsMap.put(uid, multipartRequest);
if (multipartRequest.parseRequest()) {
@@ -114,7 +114,7 @@
} finally {
if (sessionsMap != null) {
sessionsMap.remove(uid);
- sessionsMap.remove(componentId);
+ percentMap.remove(uid);
}
}
} else {
Modified:
trunk/sandbox/ui/fileUpload/src/main/java/org/richfaces/org/jboss/seam/web/MultipartRequest.java
===================================================================
---
trunk/sandbox/ui/fileUpload/src/main/java/org/richfaces/org/jboss/seam/web/MultipartRequest.java 2008-02-25
17:55:46 UTC (rev 6331)
+++
trunk/sandbox/ui/fileUpload/src/main/java/org/richfaces/org/jboss/seam/web/MultipartRequest.java 2008-02-25
17:57:31 UTC (rev 6332)
@@ -37,14 +37,14 @@
private boolean createTempFiles;
- private String clientId;
+ private String uid;
private String encoding = null;
private Integer contentLength = 0;
private int read = 0;
-
+
private Map<String, Param> parameters = null;
private Map<String, Object> percentMap = null;
@@ -246,11 +246,11 @@
private boolean shouldStop = false;
public MultipartRequest(HttpServletRequest request,
- boolean createTempFiles, int maxRequestSize, String clientId) {
+ boolean createTempFiles, int maxRequestSize, String uid) {
super(request);
this.request = request;
this.createTempFiles = createTempFiles;
- this.clientId = clientId;
+ this.uid = uid;
String contentLength = request.getHeader("Content-Length");
this.contentLength = Integer.parseInt(contentLength);
@@ -438,7 +438,8 @@
private void fillProgressInfo () {
Double percent = (Double) (100.0 * this.read / this.contentLength);
- percentMap.put(clientId, percent);
+ percentMap.put(uid, percent);
+ //this.percent = percent;
}
private byte[] getBoundaryMarker(String contentType) {
@@ -529,7 +530,7 @@
return parameters.get(name);
}
-
+
public Integer getSize() {
return contentLength;
}
Modified:
trunk/sandbox/ui/fileUpload/src/main/resources/org/richfaces/renderkit/html/js/FileUpload.js
===================================================================
---
trunk/sandbox/ui/fileUpload/src/main/resources/org/richfaces/renderkit/html/js/FileUpload.js 2008-02-25
17:55:46 UTC (rev 6331)
+++
trunk/sandbox/ui/fileUpload/src/main/resources/org/richfaces/renderkit/html/js/FileUpload.js 2008-02-25
17:57:31 UTC (rev 6332)
@@ -315,12 +315,13 @@
},
onload: function() {
+ //if (this.iframe && this.iframe.src == 'about:blank') return;
var iframeDocument = this.iframe.contentWindow.document;
var elt = iframeDocument.getElementById('_richfaces_file_upload_stopped');
var restr =
iframeDocument.getElementById('_richfaces_file_upload_size_restricted');
if (elt) {
this.callback(FileUploadEntry.UPLOAD_CANCELED);
- } if (restr) {
+ } else if (restr) {
this.callback(FileUploadEntry.UPLOAD_SIZE_ERROR);
} else {
//TODO handle server internal errors, etc.
@@ -414,8 +415,11 @@
deleteFrame: function() {
+ if (this.iframe) {
this.iframe.src = "about:blank";
document.body.removeChild(this.iframe);
+ }
+ this.iframe = null;
},
initEvents : function() {
@@ -456,7 +460,7 @@
finishProgressBar: function () {
this.progressBar.disable();
this.progressBar.setValue(100);
- //Element.hide(this._progressBar);
+ Element.hide(this._progressBar);
},
setupAutoUpload: function() {
@@ -558,7 +562,7 @@
var i = 0;
while (i < this.entries.length) {
var entry = this.entries[i];
- if (entry.state != FileUploadEntry.UPLOAD_IN_PROGRESS) {
+ if (entry.state == FileUploadEntry.UPLOAD_SUCCESS) {
this.remove(entry);
} else {
i++;
@@ -580,9 +584,10 @@
},
cleanAllDisabled: function () {
+ if (this.options['autoclear']) return true;
var c = 0;
for (var i = 0; i < this.entries.length; i++) {
- if (this.entries[i].state != FileUploadEntry.UPLOAD_IN_PROGRESS) {
+ if (this.entries[i].state == FileUploadEntry.UPLOAD_SUCCESS) {
c++;
}
}
@@ -621,7 +626,11 @@
},
disableCleanButton: function(disabled) {
- if(disabled) {
+ if (disabled)
+ Element.hide($(this.id + ":clean1"));
+ else
+ Element.show($(this.id + ":clean1"));
+ if(disabled) {
$(this.id + ":clean1").onclick = function() {return false;};
} else {
$(this.id + ":clean1").onclick = function() {return
this.clear();}.bind(this);
@@ -629,18 +638,25 @@
$(this.id+":clean1").className = (disabled? this.classes.CLEAN.DISABLED :
this.classes.CLEAN.ENABLED);
$(this.id+":clean2").className = (disabled?
this.classes.CLEAN_CONTENT.DISABLED : this.classes.CLEAN_CONTENT.ENABLED);
+
},
disableAddButton: function(disabled) {
this.currentInput.disabled = disabled;
+ if (disabled)
+ Element.hide($(this.id+":add1"));
+ else
+ Element.show($(this.id+":add1"));
$(this.id+":add1").className = (disabled? this.classes.ADD.DISABLED :
this.classes.ADD.ENABLED);
$(this.id+":add2").className = (disabled?
this.classes.ADD_CONTENT.DISABLED : this.classes.ADD_CONTENT.ENABLED);
},
disableUploadButton: function (disabled) {
if(disabled) {
+ Element.hide($(this.id + ":upload1"));
$(this.id + ":upload1").onclick = function() {return false;};
} else {
+ Element.show($(this.id + ":upload1"));
$(this.id + ":upload1").onclick = function() {return
this.upload();}.bind(this);
}
@@ -671,6 +687,9 @@
},
_endUpload: function() {
+ if (this.options['autoclear']) {
+ this.clear(this.activeEntry);
+ }
this.activeEntry = null;
this.deleteFrame();
},
@@ -719,7 +738,6 @@
//but this.runUpload can be false if upload
//has been requested to stop by user
this.setupAutoUpload();
- Element.hide(this._progressBar);
if(this.events.onuploadcomplete) {
this.element.fire("rich:onuploadcomplete", {});
}
@@ -778,7 +796,7 @@
parentForm.encoding = "multipart/form-data";
parentForm.enctype = "multipart/form-data";
parentForm.target = this.id;
- parentForm.action = oldAction + (/\?/.test(oldAction) ? '&uid' :
'?uid') + '=' + encodeURI(entry.uid) + '&clientId=' +
this.id;
+ parentForm.action = oldAction + (/\?/.test(oldAction) ? '&uid' :
'?uid') + '=' + encodeURI(entry.uid);
try {
var inputs = parentForm.elements;
Modified: trunk/sandbox/ui/fileUpload/src/main/templates/org/richfaces/fileUpload.jspx
===================================================================
---
trunk/sandbox/ui/fileUpload/src/main/templates/org/richfaces/fileUpload.jspx 2008-02-25
17:55:46 UTC (rev 6331)
+++
trunk/sandbox/ui/fileUpload/src/main/templates/org/richfaces/fileUpload.jspx 2008-02-25
17:57:31 UTC (rev 6332)
@@ -69,6 +69,7 @@
<div class="upload_button upload_font
#{component.attributes['uploadButtonClassDisabled']}"
onmouseover="this.className='upload_button_light upload_font'"
onmousedown="this.className='upload_button_press upload_font'"
onmouseup="this.className='upload_button upload_font'"
onmouseout="this.className='upload_button upload_font'"
id="#{clientId}:upload1"
+ style="display: none"
onclick="return $('#{clientId}').component.upload();">
<a href="#" class="upload_button_selection">
<div class="upload_button_content upload_font upload_ico
upload_ico_start_dis #{component.attributes['uploadButtonClassDisabled']}"
@@ -87,7 +88,8 @@
<div class="upload_button_dis upload_font
#{component.attributes['cleanButtonClassDisabled']}"
onmouseover="this.className='upload_button_light upload_font'"
onmousedown="this.className='upload_button_press upload_font'"
onmouseup="this.className='upload_button upload_font'"
onmouseout="this.className='upload_button upload_font'"
onclick="return $('#{clientId}').component.clear();"
- id="#{clientId}:clean1">
+ id="#{clientId}:clean1"
+ style="display: none">
<a href="#" class="upload_button_selection">
<div class="upload_button_content upload_font upload_ico
upload_ico_clear_dis #{component.attributes['cleanButtonClassDisabled']}"
id="#{clientId}:clean2">Clean All</div>
@@ -158,7 +160,7 @@
onerror : #{this:getAsEventHandler(context, component, "onerror")}
};
- new FileUpload('#{clientId}', #{this:getStopScript(context, component)},
#{this:getFileSizeScript(context, component)} ,'#{this:getProgressBarId(context,
component)}', FileUpload.CLASSES, #{this:getLabelMarkup(context, component)},
'#{component.attributes["maxFilesQuantity"]}', events,
#{component.attributes["disabled"]}, #{this:getAcceptedTypes(context,
component)});
+ new FileUpload('#{clientId}', #{this:getStopScript(context, component)},
#{this:getFileSizeScript(context, component)} ,'#{this:getProgressBarId(context,
component)}', FileUpload.CLASSES, #{this:getLabelMarkup(context, component)},
'#{component.attributes["maxFilesQuantity"]}', events,
#{component.attributes["disabled"]}, #{this:getAcceptedTypes(context,
component)}, {'autoclear':#{component.attributes["autoclear"]}});
</script>
</span>