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/02/01 16:35:52 UTC

svn commit: r1781267 - in /myfaces/tobago/branches/tobago-2.0.x: tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/ tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/ tobago-example/tobago-exam...

Author: weber
Date: Wed Feb  1 16:35:52 2017
New Revision: 1781267

URL: http://svn.apache.org/viewvc?rev=1781267&view=rev
Log:
TOBAGO-1690 - Drag and Drop File Upload

Modified:
    myfaces/tobago/branches/tobago-2.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUIFileDrop.java
    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/FileDropRenderer.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-file.js

Modified: myfaces/tobago/branches/tobago-2.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUIFileDrop.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-2.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUIFileDrop.java?rev=1781267&r1=1781266&r2=1781267&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-2.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUIFileDrop.java (original)
+++ myfaces/tobago/branches/tobago-2.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUIFileDrop.java Wed Feb  1 16:35:52 2017
@@ -24,9 +24,10 @@ import org.slf4j.LoggerFactory;
 
 import org.apache.myfaces.tobago.component.SupportsRenderedPartially;
 
+import javax.faces.component.ActionSource2;
 import javax.faces.event.ActionListener;
 
-public abstract class AbstractUIFileDrop extends AbstractUIFile implements SupportsRenderedPartially {
+public abstract class AbstractUIFileDrop extends AbstractUIFile implements SupportsRenderedPartially, ActionSource2 {
 
   private static final Logger LOG = LoggerFactory.getLogger(AbstractUIFileDrop.class);
 
@@ -56,4 +57,12 @@ public abstract class AbstractUIFileDrop
     this.addFacesListener(listener);
   }
 
+  public void removeActionListener(ActionListener listener) {
+    this.removeFacesListener(listener);
+  }
+
+  public ActionListener[] getActionListeners() {
+    return (ActionListener[])((ActionListener[])this.getFacesListeners(ActionListener.class));
+  }
+
 }

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=1781267&r1=1781266&r2=1781267&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 Wed Feb  1 16:35:52 2017
@@ -116,4 +116,8 @@ public class Upload {
   public List<UploadItem> getList() {
     return list;
   }
+
+  public String getDropZoneId() {
+    return "fileDropArea";
+  }
 }

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=1781267&r1=1781266&r2=1781267&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 Wed Feb  1 16:35:52 2017
@@ -62,7 +62,7 @@
         <tc:fileDrop multiple="true"
                      value="#{upload.fileDnd}"
                      action="#{upload.upload}"
-                     dropZoneId=":page:fileDropArea"/>
+                     dropZoneId="#{upload.dropZoneId}"/>
                      <!--
                      label="Drop file or click to browse"
                      tip="multiple files"

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/FileDropRenderer.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/FileDropRenderer.java?rev=1781267&r1=1781266&r2=1781267&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/FileDropRenderer.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/FileDropRenderer.java Wed Feb  1 16:35:52 2017
@@ -37,13 +37,12 @@ import org.apache.myfaces.tobago.renderk
 import org.apache.myfaces.tobago.util.ComponentUtils;
 import org.apache.myfaces.tobago.webapp.TobagoResponseWriter;
 
-import javax.el.ExpressionFactory;
 import javax.el.MethodExpression;
 import javax.el.ValueExpression;
 import javax.faces.component.UIComponent;
 import javax.faces.component.UIOutput;
 import javax.faces.context.FacesContext;
-import javax.faces.event.MethodExpressionActionListener;
+import javax.faces.event.ActionListener;
 import java.io.IOException;
 
 public class FileDropRenderer extends FileRenderer {
@@ -131,20 +130,16 @@ public class FileDropRenderer extends Fi
       }
     }
 
-    final ExpressionFactory expressionFactory = facesContext.getApplication().getExpressionFactory();
-
-    String expressionString = getExpressionString(fileDrop, Attributes.ACTION);
-    if (expressionString != null) {
-      final MethodExpression action = expressionFactory.createMethodExpression(
-          facesContext.getELContext(), expressionString, String.class, ComponentUtils.ACTION_ARGS);
-      command.setActionExpression(action);
+    MethodExpression actionExpression = fileDrop.getActionExpression();
+    if (actionExpression != null) {
+      command.setActionExpression(actionExpression);
     }
 
-    expressionString = getExpressionString(fileDrop, Attributes.ACTION_LISTENER);
-    if (expressionString != null) {
-      final MethodExpression actionListener = expressionFactory.createMethodExpression(
-          facesContext.getELContext(), expressionString, null, ComponentUtils.ACTION_LISTENER_ARGS);
-      command.addActionListener(new MethodExpressionActionListener(actionListener));
+    ActionListener[] actionListeners = fileDrop.getActionListeners();
+    if (actionListeners != null) {
+      for (ActionListener listener : actionListeners) {
+        command.addActionListener(listener);
+      }
     }
 
     fileDrop.getFacets().put("change", command);

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-file.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-file.js?rev=1781267&r1=1781266&r2=1781267&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-file.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-file.js Wed Feb  1 16:35:52 2017
@@ -128,8 +128,13 @@ Tobago.registerListener(Tobago.File.init
     findDropElement: function (dropZoneId) {
       if (dropZoneId.charAt(0) == ":" && dropZoneId.charAt(1) != ":") {
         return jQuery(Tobago.Utils.escapeClientId(dropZoneId.substring(1)));
-      } else  {
-        // TODO
+      } else if (!dropZoneId.contains(":")) {
+        // in same namingContainer as this.element
+        var elementId = this.element.attr("id");
+        var prefix = elementId.substring(0, elementId.lastIndexOf(":") + 1);
+        return jQuery(Tobago.Utils.escapeClientId(prefix + dropZoneId));
+      } else {
+        // TODO resolve relative :: ids
         return jQuery(Tobago.Utils.escapeClientId(dropZoneId));
       }
     },
@@ -163,8 +168,10 @@ Tobago.registerListener(Tobago.File.init
 
     show: function () {
       // console.info("show");  // @DEV_ONLY
-      this.fileDropArea.css({display: ''});
-      this.fileDropArea.on("drop", this.filesDropped);
+      if (this.element.find("input[type='file']").prop('disabled') === false) {
+        this.fileDropArea.css({display: ''});
+        this.fileDropArea.on("drop", this.filesDropped);
+      }
     },
 
     hide: function () {