myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lu4...@apache.org
Subject svn commit: r1521301 - in /myfaces/core/trunk/shared/src/main/java/org/apache/myfaces/shared/renderkit/html: HtmlInputFileRendererBase.java util/HttpPartWrapper.java
Date Mon, 09 Sep 2013 22:02:57 GMT
Author: lu4242
Date: Mon Sep  9 22:02:57 2013
New Revision: 1521301

URL: http://svn.apache.org/r1521301
Log:
MYFACES-3716 Implement h:inputFile (thanks to Dora Rajappan for help with this issue)

Added:
    myfaces/core/trunk/shared/src/main/java/org/apache/myfaces/shared/renderkit/html/util/HttpPartWrapper.java
  (with props)
Modified:
    myfaces/core/trunk/shared/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlInputFileRendererBase.java

Modified: myfaces/core/trunk/shared/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlInputFileRendererBase.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/shared/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlInputFileRendererBase.java?rev=1521301&r1=1521300&r2=1521301&view=diff
==============================================================================
--- myfaces/core/trunk/shared/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlInputFileRendererBase.java
(original)
+++ myfaces/core/trunk/shared/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlInputFileRendererBase.java
Mon Sep  9 22:02:57 2013
@@ -32,11 +32,18 @@ import java.util.List;
 import java.util.Map;
 import java.util.logging.Level;
 import java.util.logging.Logger;
+import javax.faces.FacesException;
+import javax.faces.application.FacesMessage;
+import javax.faces.application.ProjectStage;
 import javax.faces.component.UIViewRoot;
 import javax.faces.component.behavior.ClientBehavior;
 import javax.faces.component.behavior.ClientBehaviorHolder;
+import javax.faces.component.html.HtmlForm;
 import javax.faces.component.html.HtmlInputText;
+import org.apache.myfaces.shared.renderkit.html.util.FormInfo;
+import org.apache.myfaces.shared.renderkit.html.util.HttpPartWrapper;
 import org.apache.myfaces.shared.renderkit.html.util.JavascriptUtils;
+import org.apache.myfaces.shared.util._ComponentUtils;
 
 /**
  * @author Werner Punz (latest modification by $Author$)
@@ -52,7 +59,6 @@ public class HtmlInputFileRendererBase e
     @Override
     public void decode(FacesContext facesContext, UIComponent component)
     {
-        //TODO: implement me!
         try
         {
            Part part = ((HttpServletRequest) facesContext.getExternalContext().getRequest()).
@@ -62,15 +68,15 @@ public class HtmlInputFileRendererBase e
            {
                return;
            }
-           ((UIInput) component).setSubmittedValue(part);
+           ((UIInput) component).setSubmittedValue(new HttpPartWrapper(part));
         }
         catch (IOException e)
         {
-           e.printStackTrace();
+            throw new FacesException(e);
         }
         catch (ServletException e)
         {
-           e.printStackTrace();
+            throw new FacesException(e);
         }
         
         if (component instanceof ClientBehaviorHolder &&
@@ -86,27 +92,25 @@ public class HtmlInputFileRendererBase e
     {   
         renderInput(facesContext, component);
         
-        // TODO: "... verify that the enclosing form has an enctype ..." is different than
-        // "... check the incoming request has an enctype ...". The code below do that, but
-        // what we really want to do is check if there is a parent in the component
-        // hierarchy that is UIForm and has "multipart/form-data" content type. I'll comment
-        // this code temporally.
-        /*
         if(!facesContext.isProjectStage(ProjectStage.Production) 
               && facesContext.isPostback() &&
              (facesContext.getPartialViewContext().isPartialRequest() ||
               facesContext.getPartialViewContext().isAjaxRequest()))
         {
-            String content = ((HttpServletRequest) facesContext.getExternalContext()
-                 .getRequest()).getContentType();
-            if(content==null || !content.contains("multipart/form-data"))
-            {
-                 //Add facemessage
-                 FacesMessage message = new FacesMessage("file upload requires a form with"+
-                 " enctype equal to multipart/form-data");
-                 facesContext.addMessage(component.getClientId(), message);
+            FormInfo formInfo = _ComponentUtils.findNestingForm(component, facesContext);
+            if (formInfo != null && formInfo.getForm() instanceof HtmlForm)
+            {
+                HtmlForm form = (HtmlForm) formInfo.getForm();
+                String content = form.getEnctype();
+                if(content==null || !content.contains("multipart/form-data"))
+                {
+                     //Add facemessage
+                     FacesMessage message = new FacesMessage("file upload requires a form
with"+
+                            " enctype equal to multipart/form-data");
+                     facesContext.addMessage(component.getClientId(), message);
+                }
             }
-        }*/
+        }
     }
    
     public Object getConvertedValue(FacesContext context, UIComponent component, Object submittedValue)

Added: myfaces/core/trunk/shared/src/main/java/org/apache/myfaces/shared/renderkit/html/util/HttpPartWrapper.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/shared/src/main/java/org/apache/myfaces/shared/renderkit/html/util/HttpPartWrapper.java?rev=1521301&view=auto
==============================================================================
--- myfaces/core/trunk/shared/src/main/java/org/apache/myfaces/shared/renderkit/html/util/HttpPartWrapper.java
(added)
+++ myfaces/core/trunk/shared/src/main/java/org/apache/myfaces/shared/renderkit/html/util/HttpPartWrapper.java
Mon Sep  9 22:02:57 2013
@@ -0,0 +1,114 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.shared.renderkit.html.util;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Collection;
+import javax.faces.FacesWrapper;
+import javax.faces.component.StateHolder;
+import javax.faces.context.FacesContext;
+import javax.servlet.http.Part;
+
+/**
+ *
+ * @author Leonardo Uribe
+ */
+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 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;
+    }
+    
+}

Propchange: myfaces/core/trunk/shared/src/main/java/org/apache/myfaces/shared/renderkit/html/util/HttpPartWrapper.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message