myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lof...@apache.org
Subject svn commit: r1733614 - in /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 util/HttpPartWrapper.java
Date Fri, 04 Mar 2016 16:45:54 GMT
Author: lofwyr
Date: Fri Mar  4 16:45:54 2016
New Revision: 1733614

URL: http://svn.apache.org/viewvc?rev=1733614&view=rev
Log:
TOBAGO-1539: Using Servlet 3.0 for uploading files with <tc:file>
* don't save state for the Part: this fixes a problem after failed validation

Added:
    myfaces/tobago/branches/tobago-3.0.x/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/util/HttpPartWrapper.java
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

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=1733614&r1=1733613&r2=1733614&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
Fri Mar  4 16:45:54 2016
@@ -27,6 +27,7 @@ import org.apache.myfaces.tobago.renderk
 import org.apache.myfaces.tobago.renderkit.html.HtmlElements;
 import org.apache.myfaces.tobago.renderkit.html.HtmlInputTypes;
 import org.apache.myfaces.tobago.renderkit.html.util.HtmlRendererUtils;
+import org.apache.myfaces.tobago.renderkit.util.HttpPartWrapper;
 import org.apache.myfaces.tobago.util.ComponentUtils;
 import org.apache.myfaces.tobago.webapp.TobagoResponseWriter;
 import org.slf4j.Logger;
@@ -72,7 +73,7 @@ public class FileRenderer extends InputR
           LOG.debug("Uploaded file '{}', size={}, type='{}'",
               PartUtils.getSubmittedFileName(part), part.getSize(), part.getContentType());
         }
-        input.setSubmittedValue(part);
+        input.setSubmittedValue(new HttpPartWrapper(part));
       } catch (Exception e) {
         LOG.error("", e);
         input.setValid(false);

Added: myfaces/tobago/branches/tobago-3.0.x/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/util/HttpPartWrapper.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/util/HttpPartWrapper.java?rev=1733614&view=auto
==============================================================================
--- myfaces/tobago/branches/tobago-3.0.x/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/util/HttpPartWrapper.java
(added)
+++ myfaces/tobago/branches/tobago-3.0.x/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/util/HttpPartWrapper.java
Fri Mar  4 16:45:54 2016
@@ -0,0 +1,96 @@
+package org.apache.myfaces.tobago.renderkit.util;
+
+import javax.faces.FacesException;
+import javax.faces.FacesWrapper;
+import javax.faces.component.StateHolder;
+import javax.faces.context.FacesContext;
+import javax.servlet.http.Part;
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.Collection;
+
+public class HttpPartWrapper implements Part, FacesWrapper<Part>, StateHolder {
+  private Part delegate;
+
+  public HttpPartWrapper() {
+  }
+
+  public HttpPartWrapper(Part delegate) {
+    this.delegate = delegate;
+  }
+
+  public void delete() throws IOException {
+    getWrapped().delete();
+  }
+
+  public String getContentType() {
+    return getWrapped().getContentType();
+  }
+
+  public String getHeader(String headerName) {
+    return getWrapped().getHeader(headerName);
+  }
+
+  public Collection<String> getHeaderNames() {
+    return getWrapped().getHeaderNames();
+  }
+
+  public Collection<String> getHeaders(String headerName) {
+    return getWrapped().getHeaders(headerName);
+  }
+
+  public InputStream getInputStream() throws IOException {
+    return getWrapped().getInputStream();
+  }
+
+  public String getName() {
+    return getWrapped().getName();
+  }
+
+  public long getSize() {
+    return getWrapped().getSize();
+  }
+
+  public void write(String fileName) throws IOException {
+    getWrapped().write(fileName);
+  }
+
+  public String getSubmittedFileName() {
+    Part wrapped = getWrapped();
+    try {
+      Method m = wrapped.getClass().getMethod("getSubmittedFileName");
+      return (String) m.invoke(wrapped);
+    } catch (NoSuchMethodException ex) {
+      throw new FacesException(ex);
+    } catch (SecurityException ex) {
+      throw new FacesException(ex);
+    } catch (IllegalAccessException ex) {
+      throw new FacesException(ex);
+    } catch (IllegalArgumentException ex) {
+      throw new FacesException(ex);
+    } catch (InvocationTargetException ex) {
+      throw new FacesException(ex);
+    }
+  }
+
+  public Object saveState(FacesContext context) {
+    return null;
+  }
+
+  public void restoreState(FacesContext context, Object state) {
+  }
+
+  public boolean isTransient() {
+    return true;
+  }
+
+  public void setTransient(boolean newTransientValue) {
+  }
+
+  public Part getWrapped() {
+    return delegate;
+  }
+
+}



Mime
View raw message