You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by we...@apache.org on 2017/01/24 13:28:19 UTC

svn commit: r1780073 - in /myfaces/tobago/branches/tobago-2.0.x: tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/ tobago-example/tobago-example-demo/src/main/webapp/content/40-upload/ tobago-theme/tobago-theme-st...

Author: weber
Date: Tue Jan 24 13:28:19 2017
New Revision: 1780073

URL: http://svn.apache.org/viewvc?rev=1780073&view=rev
Log:
TOBAGO-1683 - Tobago 2.0: File upload should work with AJAX

Modified:
    myfaces/tobago/branches/tobago-2.0.x/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/Upload.java
    myfaces/tobago/branches/tobago-2.0.x/tobago-example/tobago-example-demo/src/main/webapp/content/40-upload/upload.xhtml
    myfaces/tobago/branches/tobago-2.0.x/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/FileRenderer.java
    myfaces/tobago/branches/tobago-2.0.x/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago.js

Modified: myfaces/tobago/branches/tobago-2.0.x/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/Upload.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-2.0.x/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/Upload.java?rev=1780073&r1=1780072&r2=1780073&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-2.0.x/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/Upload.java (original)
+++ myfaces/tobago/branches/tobago-2.0.x/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/Upload.java Tue Jan 24 13:28:19 2017
@@ -33,6 +33,7 @@ public class Upload {
   private FileItem file1;
   private FileItem file2;
   private FileItem[] fileMulti;
+  private FileItem[] fileAjax;
 
   private List<UploadItem> list = new ArrayList<UploadItem>();
 
@@ -40,6 +41,7 @@ public class Upload {
    upload(file1);
    upload(file2);
    upload(fileMulti);
+   upload(fileAjax);
       return null;
     }
 
@@ -93,6 +95,14 @@ public class Upload {
     this.fileMulti = fileMulti;
   }
 
+  public FileItem[] getFileAjax() {
+    return fileAjax;
+  }
+
+  public void setFileAjax(FileItem[] fileAjax) {
+    this.fileAjax = fileAjax;
+  }
+
   public List<UploadItem> getList() {
     return list;
   }

Modified: myfaces/tobago/branches/tobago-2.0.x/tobago-example/tobago-example-demo/src/main/webapp/content/40-upload/upload.xhtml
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-2.0.x/tobago-example/tobago-example-demo/src/main/webapp/content/40-upload/upload.xhtml?rev=1780073&r1=1780072&r2=1780073&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-2.0.x/tobago-example/tobago-example-demo/src/main/webapp/content/40-upload/upload.xhtml (original)
+++ myfaces/tobago/branches/tobago-2.0.x/tobago-example/tobago-example-demo/src/main/webapp/content/40-upload/upload.xhtml Tue Jan 24 13:28:19 2017
@@ -23,7 +23,7 @@
                 xmlns:ui="http://java.sun.com/jsf/facelets"
                 xmlns:f="http://java.sun.com/jsf/core">
   <ui:param name="title" value="File Upload"/>
-  <tc:panel>
+  <tc:panel id="uploadPanel">
     <f:facet name="layout">
       <tc:gridLayout rows="auto;auto;*"/>
     </f:facet>
@@ -45,6 +45,13 @@
       <tx:file multiple="true" label="Upload multiple:" value="#{upload.fileMulti}" tip="multiple files"/>
       <tc:panel/>
 
+      <tx:file label="Upload ajax:" multiple="true" value="#{upload.fileAjax}" tip="multiple files">
+        <f:facet name="change">
+          <tc:command action="#{upload.upload}" renderedPartially="uploadPanel"/>
+        </f:facet>
+      </tx:file>
+      <tc:panel/>
+
     </tc:panel>
 
     <tc:sheet var="entry" value="#{upload.list}" columns="*;*;*">

Modified: myfaces/tobago/branches/tobago-2.0.x/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/FileRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-2.0.x/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/FileRenderer.java?rev=1780073&r1=1780072&r2=1780073&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-2.0.x/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/FileRenderer.java (original)
+++ myfaces/tobago/branches/tobago-2.0.x/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/FileRenderer.java Tue Jan 24 13:28:19 2017
@@ -155,6 +155,7 @@ public class FileRenderer extends InputR
     if (title != null) {
       writer.writeAttribute(HtmlAttributes.TITLE, title, true);
     }
+    HtmlRendererUtils.renderCommandFacet(file, facesContext, writer);
     writer.endElement(HtmlElements.INPUT);
 
     writer.endElement(HtmlElements.DIV);

Modified: myfaces/tobago/branches/tobago-2.0.x/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago.js
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-2.0.x/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago.js?rev=1780073&r1=1780072&r2=1780073&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-2.0.x/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago.js (original)
+++ myfaces/tobago/branches/tobago-2.0.x/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago.js Tue Jan 24 13:28:19 2017
@@ -1929,7 +1929,15 @@ Tobago.Transport.JqueryTransport = {
       requestObject.url = requestOptions.url;
       Tobago.action.value = requestOptions.actionId;
       Tobago.partialRequestIds.value = requestOptions.ajaxComponentIds;
-      requestObject.data = jQuery(Tobago.form).serialize();
+      var form = jQuery(Tobago.form);
+      console.debug("enctype: " + form.attr("enctype")); // @DEV_ONLY
+      if ((form.attr("enctype")|| "").toLocaleLowerCase() == "multipart/form-data") {
+        requestObject.data = new FormData(Tobago.form);
+        requestObject.processData = false;
+        requestObject.contentType = false;
+      } else {
+        requestObject.data = form.serialize();
+      }
       requestOptions.xhr = jQuery.ajax(requestObject);
     }, false, requestOptions.actionId);
   }