Author: andrei_exadel
Date: 2008-03-13 10:59:33 -0400 (Thu, 13 Mar 2008)
New Revision: 6782
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:
RF-2474
Modified:
trunk/ui/fileUpload/src/main/java/org/richfaces/renderkit/FileUploadRendererBase.java
===================================================================
---
trunk/ui/fileUpload/src/main/java/org/richfaces/renderkit/FileUploadRendererBase.java 2008-03-13
14:04:27 UTC (rev 6781)
+++
trunk/ui/fileUpload/src/main/java/org/richfaces/renderkit/FileUploadRendererBase.java 2008-03-13
14:59:33 UTC (rev 6782)
@@ -30,6 +30,8 @@
import org.ajax4jsf.javascript.JSReference;
import org.ajax4jsf.javascript.ScriptUtils;
import org.ajax4jsf.renderkit.AjaxRendererUtils;
+import org.ajax4jsf.renderkit.ComponentVariables;
+import org.ajax4jsf.renderkit.ComponentsVariableResolver;
import org.ajax4jsf.renderkit.RendererUtils;
import org.ajax4jsf.request.MultipartRequest;
import org.ajax4jsf.resource.CountingOutputWriter;
@@ -120,6 +122,35 @@
}
}
+
+ /**
+ * Gets form id
+ * @param context - faces context
+ * @param component - component
+ * @return String form id
+ */
+ public String getFormId(FacesContext context, UIComponent component) {
+ UIComponent form = AjaxRendererUtils.getNestingForm(component);
+ if (form != null) {
+ return form.getClientId(context);
+ }
+ return "";
+ }
+
+
+ /**
+ * Gets container id
+ * @param context - faces context
+ * @param component - component
+ * @return String container id
+ */
+ public String getContainerId(FacesContext context, UIComponent component) {
+ UIComponent container = (UIComponent)AjaxRendererUtils.findAjaxContainer(context,
component);
+ if (container != null) {
+ return container.getClientId(context);
+ }
+ return null;
+ }
/**
* Generates map with internalized labels to be put into JS
@@ -337,9 +368,16 @@
@SuppressWarnings("unchecked")
private String getActionScript(FacesContext context, UIComponent component,
String action, Object oncomplete) throws IOException {
- JSFunction ajaxFunction = AjaxRendererUtils.buildAjaxFunction(
- component, context);
+ ComponentVariables variables = ComponentsVariableResolver.getVariables(this,
component);
String clientId = component.getClientId(context);
+ String containerId = (String)variables.getVariable("containerId");
+ JSFunction ajaxFunction = new JSFunction(AjaxRendererUtils.AJAX_FUNCTION_NAME);
+ ajaxFunction.addParameter(containerId);
+ ajaxFunction.addParameter(new JSReference("formId"));
+ ajaxFunction.addParameter(new JSReference("event"));
+// AjaxRendererUtils.buildAjaxFunction(
+// component, context);
+
Map options = AjaxRendererUtils.buildEventOptions(context, component);
Map parameters = (Map) options.get("parameters");
parameters.put("action", action);
@@ -351,6 +389,7 @@
ajaxFunction.addParameter(options);
JSFunctionDefinition function = new JSFunctionDefinition("uid");
+ function.addParameter("formId");
function.addParameter("event");
function.addToBody(ajaxFunction.toScript());
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-03-13
14:04:27 UTC (rev 6781)
+++
trunk/ui/fileUpload/src/main/resources/org/richfaces/renderkit/html/js/FileUpload.js 2008-03-13
14:59:33 UTC (rev 6782)
@@ -168,7 +168,7 @@
},
stop: function() {
- this.uploadObject.stopScript(this.uid);
+ this.uploadObject.stopScript(this.uid, this.uploadObject.formId);
},
_clearInput: function() {
@@ -373,9 +373,17 @@
uploadedCount: 0,
- initialize: function(id, stopScript, getFileSizeScript, progressBarId, classes, label,
maxFiles, events, disabled, acceptedTypes, options, labels) {
+ initialize: function(id, formId, stopScript, getFileSizeScript, progressBarId, classes,
label, maxFiles, events, disabled, acceptedTypes, options, labels) {
this.id = id;
this.element = $(this.id);
+ if (formId != '') {
+ this.formId = formId;
+ this.form = $(formId);
+ }else {
+ var f = this._getForm();
+ this.formId = (f) ? f.id : null;
+ this.form = f;
+ }
this._progressBar = $(progressBarId);
this.progressBar = this._progressBar.component;
this.entries = new Array();
@@ -480,7 +488,7 @@
}
}else {
if (this.activeEntry)
- this.getFileSizeScript(this.activeEntry.uid);
+ this.getFileSizeScript(this.activeEntry.uid, this.formId);
}
},
@@ -839,9 +847,13 @@
},
getForm: function () {
+ return this.form;
+ },
+
+ _getForm: function () {
var parentForm = this.element;
while (parentForm.tagName && parentForm.tagName.toLowerCase() !=
'form') {
- parentForm = parentForm.parentNode;
+ parentForm = parentForm.firstChild;
}
return parentForm;
},
@@ -921,7 +933,7 @@
parentForm.target = oldTarget;
parentForm.encoding = oldEncoding;
parentForm.enctype = oldEnctype;
- this.getFileSizeScript(entry.uid);
+ this.getFileSizeScript(entry.uid, this.formId);
}
}
Modified: trunk/ui/fileUpload/src/main/templates/org/richfaces/fileUpload.jspx
===================================================================
--- trunk/ui/fileUpload/src/main/templates/org/richfaces/fileUpload.jspx 2008-03-13
14:04:27 UTC (rev 6781)
+++ trunk/ui/fileUpload/src/main/templates/org/richfaces/fileUpload.jspx 2008-03-13
14:59:33 UTC (rev 6782)
@@ -17,7 +17,8 @@
/org/richfaces/renderkit/html/scripts/utils.js,
/org/richfaces/renderkit/html/scripts/json/json-dom.js,
/org/richfaces/renderkit/html/js/FileUpload.js,
- /org/richfaces/renderkit/html/js/progressBar.js
+ /org/richfaces/renderkit/html/js/progressBar.js,
+ /org/ajax4jsf/javascript/scripts/form.js,
</h:scripts>
<f:clientId var="clientId" />
@@ -39,13 +40,16 @@
variables.setVariable("addLabel",labels.get("add"));
variables.setVariable("uploadLabel",labels.get("upload"));
variables.setVariable("clearAllLabel",labels.get("clear_all"));
-
+ variables.setVariable("formId",getFormId(context, component));
+ variables.setVariable("containerId",getContainerId(context, component));
+
]]>
</jsp:scriptlet>
<div class="upload_list_decor" style="width:
#{component.attributes['listWidth']}" id="#{clientId}">
+<f:call name="utils.encodeBeginFormIfNessesary" />
<!-- iframe name="ddd" id="#{clientId}_iframe"
style="display: none;"/ -->
@@ -166,10 +170,10 @@
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)},
{'autoclear':#{component.attributes["autoclear"]}},#{this:_getLabels(labels)});
+ new FileUpload('#{clientId}','#{formId}',#{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"]}},#{this:_getLabels(labels)});
</script>
</span>
-
+<f:call name="utils.encodeEndFormIfNessesary" />
</div>