You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lo...@apache.org on 2016/03/09 14:04:23 UTC

svn commit: r1734232 - in /myfaces/tobago/branches/tobago-3.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: lofwyr
Date: Wed Mar  9 13:04:22 2016
New Revision: 1734232

URL: http://svn.apache.org/viewvc?rev=1734232&view=rev
Log:
TOBAGO-1524: Use standard ajax mechanism
* AJAX for File Upload

Modified:
    myfaces/tobago/branches/tobago-3.0.x/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/Upload.java
    myfaces/tobago/branches/tobago-3.0.x/tobago-example/tobago-example-demo/src/main/webapp/content/40-upload/upload.xhtml
    myfaces/tobago/branches/tobago-3.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-3.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-3.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-3.0.x/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/Upload.java?rev=1734232&r1=1734231&r2=1734232&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-3.0.x/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/Upload.java (original)
+++ myfaces/tobago/branches/tobago-3.0.x/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/Upload.java Wed Mar  9 13:04:22 2016
@@ -26,6 +26,7 @@ import org.slf4j.LoggerFactory;
 import javax.enterprise.context.SessionScoped;
 import javax.faces.application.FacesMessage;
 import javax.faces.context.FacesContext;
+import javax.faces.event.AjaxBehaviorEvent;
 import javax.inject.Named;
 import javax.servlet.http.Part;
 import java.io.Serializable;
@@ -40,6 +41,7 @@ public class Upload implements Serializa
 
   private Part file1;
   private Part file2;
+  private Part file3;
 
   private List<UploadItem> list = new ArrayList<UploadItem>();
 
@@ -49,6 +51,10 @@ public class Upload implements Serializa
     return null;
   }
 
+  public void uploadAjax(AjaxBehaviorEvent event) {
+    upload(file3);
+  }
+
   public void upload(Part part) {
     LOG.info("checking file item");
     if (part == null || part.getSize() == 0) {
@@ -81,6 +87,14 @@ public class Upload implements Serializa
     this.file2 = file2;
   }
 
+  public Part getFile3() {
+    return file3;
+  }
+
+  public void setFile3(Part file3) {
+    this.file3 = file3;
+  }
+
   public List<UploadItem> getList() {
     return list;
   }

Modified: myfaces/tobago/branches/tobago-3.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-3.0.x/tobago-example/tobago-example-demo/src/main/webapp/content/40-upload/upload.xhtml?rev=1734232&r1=1734231&r2=1734232&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-3.0.x/tobago-example/tobago-example-demo/src/main/webapp/content/40-upload/upload.xhtml (original)
+++ myfaces/tobago/branches/tobago-3.0.x/tobago-example/tobago-example-demo/src/main/webapp/content/40-upload/upload.xhtml Wed Mar  9 13:04:22 2016
@@ -20,9 +20,10 @@
 <ui:composition template="/main.xhtml"
                 xmlns:tc="http://myfaces.apache.org/tobago/component"
                 xmlns:ui="http://java.sun.com/jsf/facelets"
+                xmlns:f="http://java.sun.com/jsf/core"
                 xmlns="http://www.w3.org/1999/xhtml">
   <ui:param name="title" value="File Upload"/>
-  <tc:panel>
+  <tc:panel id="panel">
 
     <p>
       To load up files to the server for JSF 2.0 and 2.1 you will need to
@@ -55,7 +56,11 @@
 
     <tc:button label="Submit" defaultCommand="true" action="#{upload.upload}"/>
 
-    <tc:sheet var="entry" value="#{upload.list}" columns="*;*;*">
+    <tc:file label="Instant" value="#{upload.file3}" tip="with AJAX" id="file3">
+      <f:ajax listener="#{upload.uploadAjax}" render="panel"/>
+    </tc:file>
+
+    <tc:sheet id="sheet" var="entry" value="#{upload.list}" columns="*;*;*">
 
       <tc:column label="Name">
         <tc:out value="#{entry.name}"/>

Modified: myfaces/tobago/branches/tobago-3.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-3.0.x/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/FileRenderer.java?rev=1734232&r1=1734231&r2=1734232&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-3.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-3.0.x/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/FileRenderer.java Wed Mar  9 13:04:22 2016
@@ -23,6 +23,7 @@ import org.apache.myfaces.tobago.interna
 import org.apache.myfaces.tobago.internal.util.FacesContextUtils;
 import org.apache.myfaces.tobago.internal.util.PartUtils;
 import org.apache.myfaces.tobago.renderkit.css.Classes;
+import org.apache.myfaces.tobago.renderkit.html.DataAttributes;
 import org.apache.myfaces.tobago.renderkit.html.HtmlAttributes;
 import org.apache.myfaces.tobago.renderkit.html.HtmlElements;
 import org.apache.myfaces.tobago.renderkit.html.HtmlInputTypes;
@@ -127,6 +128,12 @@ public class FileRenderer extends InputR
     if (title != null) {
       writer.writeAttribute(HtmlAttributes.TITLE, title, true);
     }
+
+    final String commands = RenderUtils.getBehaviorCommands(facesContext, file);
+    if (commands != null) {
+      writer.writeAttribute(DataAttributes.COMMANDS, commands, true);
+    }
+
     writer.endElement(HtmlElements.INPUT);
   }
 

Modified: myfaces/tobago/branches/tobago-3.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-3.0.x/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago.js?rev=1734232&r1=1734231&r2=1734232&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-3.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-3.0.x/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago.js Wed Mar  9 13:04:22 2016
@@ -805,7 +805,7 @@ var Tobago = {
         if (commands.change.partially) {
           //Tobago.reloadComponent(this, commands.change.partially, commands.change.action, commands.change);
           jsf.ajax.request(
-              jQuery(this).attr("id"),
+              jQuery(this).attr("name"),
               event,
               {
                 "javax.faces.behavior.event": "change",