Author: nbelaevski
Date: 2010-12-10 12:37:50 -0500 (Fri, 10 Dec 2010)
New Revision: 20509
Added:
trunk/ui/input/ui/src/main/java/org/richfaces/resource/
trunk/ui/input/ui/src/main/java/org/richfaces/resource/FileUploadProgressResource.java
Modified:
trunk/ui/input/ui/src/main/java/org/richfaces/component/AbstractFileUpload.java
trunk/ui/input/ui/src/main/java/org/richfaces/context/FileUploadPartialViewContextFactory.java
trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/fileupload.js
trunk/ui/input/ui/src/main/resources/META-INF/richfaces/resource-mappings.properties
trunk/ui/output/ui/src/main/java/org/richfaces/component/AbstractProgressBar.java
Log:
File upload switched to progress bar using resource GET polling
Modified: trunk/ui/input/ui/src/main/java/org/richfaces/component/AbstractFileUpload.java
===================================================================
---
trunk/ui/input/ui/src/main/java/org/richfaces/component/AbstractFileUpload.java 2010-12-10
17:27:16 UTC (rev 20508)
+++
trunk/ui/input/ui/src/main/java/org/richfaces/component/AbstractFileUpload.java 2010-12-10
17:37:50 UTC (rev 20509)
@@ -37,9 +37,8 @@
import org.richfaces.cdk.annotations.JsfComponent;
import org.richfaces.cdk.annotations.JsfRenderer;
import org.richfaces.cdk.annotations.Tag;
-import org.richfaces.context.FileUploadPartialViewContextFactory;
import org.richfaces.event.FileUploadListener;
-import org.richfaces.request.MultipartRequest;
+import org.richfaces.renderkit.RenderKitUtils;
/**
* @author Konstantin Mishin
@@ -85,16 +84,14 @@
}
}
if (component != null) {
- component.setValueExpression("value",
context.getApplication().getExpressionFactory()
- .createValueExpression(context.getELContext(),
- "#{" + MultipartRequest.PERCENT_BEAN_NAME +
"[param['"
- + FileUploadPartialViewContextFactory.UID_KEY + "']]}",
Integer.class));
+ String resourcePath = RenderKitUtils.getResourcePath(context,
"org.richfaces", "fileUploadProgress");
+ component.getAttributes().put("resource", resourcePath);
}
}
/**
* <p>Add a new {@link FileUploadListener} to the set of listeners
- * interested in being notified when {@link UploadEvent}s occur.</p>
+ * interested in being notified when {@link org.richfaces.UploadEvent}s
occur.</p>
*
* @param listener The {@link FileUploadListener} to be added
* @throws NullPointerException if <code>listener</code>
Modified:
trunk/ui/input/ui/src/main/java/org/richfaces/context/FileUploadPartialViewContextFactory.java
===================================================================
---
trunk/ui/input/ui/src/main/java/org/richfaces/context/FileUploadPartialViewContextFactory.java 2010-12-10
17:27:16 UTC (rev 20508)
+++
trunk/ui/input/ui/src/main/java/org/richfaces/context/FileUploadPartialViewContextFactory.java 2010-12-10
17:37:50 UTC (rev 20509)
@@ -52,6 +52,8 @@
public static final String UID_KEY = "rf_fu_uid";
+ public static final String UID_ALT_KEY = "rf_fu_uid_alt";
+
private static enum ResponseState {
sizeExceeded, stopped, serverError
};
Added:
trunk/ui/input/ui/src/main/java/org/richfaces/resource/FileUploadProgressResource.java
===================================================================
---
trunk/ui/input/ui/src/main/java/org/richfaces/resource/FileUploadProgressResource.java
(rev 0)
+++
trunk/ui/input/ui/src/main/java/org/richfaces/resource/FileUploadProgressResource.java 2010-12-10
17:37:50 UTC (rev 20509)
@@ -0,0 +1,52 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.resource;
+
+import java.util.Map;
+
+import javax.faces.context.FacesContext;
+
+import org.richfaces.context.FileUploadPartialViewContextFactory;
+import org.richfaces.request.MultipartRequest;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class FileUploadProgressResource extends AbstractJSONResource {
+
+ @Override
+ protected Object getData(FacesContext context) {
+ Map<String, Object> sessionMap =
context.getExternalContext().getSessionMap();
+ Map<String, Number> percentMap = (Map<String, Number>)
sessionMap.get(MultipartRequest.PERCENT_BEAN_NAME);
+
+ Number result = null;
+
+ if (percentMap != null) {
+ String uploadId =
context.getExternalContext().getRequestParameterMap().get(FileUploadPartialViewContextFactory.UID_ALT_KEY);
+ result = (Number) percentMap.get(uploadId);
+ }
+
+ return result != null ? result : 0;
+ }
+
+}
Modified:
trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/fileupload.js
===================================================================
---
trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/fileupload.js 2010-12-10
17:27:16 UTC (rev 20508)
+++
trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/fileupload.js 2010-12-10
17:37:50 UTC (rev 20509)
@@ -23,6 +23,8 @@
var UID = "rf_fu_uid";
+ var UID_ALT = "rf_fu_uid_alt";
+
var ITEM_HTML = '<div class="rf-fu-itm">'
+ '<span class="rf-fu-itm-lft"><span
class="rf-fu-itm-lbl"/><span
class="rf-fu-itm-st"/></span>'
+ '<span class="rf-fu-itm-rgh"><a
href="javascript:void(0)"
class="rf-fu-itm-lnk"/></span></div>';
@@ -251,11 +253,12 @@
this.model.state = ITEM_STATE.UPLOADING;
this.uid = Math.random();
this.fileUpload.__submit();
- var params = {};
- params[UID] = this.uid;
if (this.fileUpload.progressBar) {
this.fileUpload.progressBar.setValue(0);
this.state.html(this.fileUpload.progressBarElement.detach());
+
+ var params = {};
+ params[UID_ALT] = this.uid;
this.fileUpload.progressBar.enable(params);
}
},
Modified:
trunk/ui/input/ui/src/main/resources/META-INF/richfaces/resource-mappings.properties
===================================================================
---
trunk/ui/input/ui/src/main/resources/META-INF/richfaces/resource-mappings.properties 2010-12-10
17:27:16 UTC (rev 20508)
+++
trunk/ui/input/ui/src/main/resources/META-INF/richfaces/resource-mappings.properties 2010-12-10
17:37:50 UTC (rev 20509)
@@ -14,4 +14,5 @@
org.richfaces.images\:fuBtnGrad.png=org.richfaces.renderkit.html.BaseGradient\
{baseColorParam=additionalBackgroundColor, gradientColorParam=trimColor, height=18,
width=1}
org.richfaces.images\:fuBtnDisGrad.png=org.richfaces.renderkit.html.BaseGradient\
- {baseColorParam=tableSubfooterBackgroundColor,
gradientColorParam=tableFooterBackgroundColor, height=18, width=1}
\ No newline at end of file
+ {baseColorParam=tableSubfooterBackgroundColor,
gradientColorParam=tableFooterBackgroundColor, height=18, width=1}
+org.richfaces\:fileUploadProgress=org.richfaces.resource.FileUploadProgressResource
\ No newline at end of file
Modified:
trunk/ui/output/ui/src/main/java/org/richfaces/component/AbstractProgressBar.java
===================================================================
---
trunk/ui/output/ui/src/main/java/org/richfaces/component/AbstractProgressBar.java 2010-12-10
17:27:16 UTC (rev 20508)
+++
trunk/ui/output/ui/src/main/java/org/richfaces/component/AbstractProgressBar.java 2010-12-10
17:37:50 UTC (rev 20509)
@@ -135,6 +135,9 @@
@Attribute
public abstract Object getValue();
+ @Attribute(hidden = true)
+ public abstract String getResource();
+
public void encodeMetaComponent(FacesContext context, String metaComponentId) throws
IOException {
((MetaComponentRenderer) getRenderer(context)).encodeMetaComponent(context, this,
metaComponentId);
}