myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hno...@apache.org
Subject [myfaces-tobago] branch master updated: TOBAGO-1928 Required has no effect for tc:file
Date Mon, 17 Sep 2018 14:57:32 GMT
This is an automated email from the ASF dual-hosted git repository.

hnoeth pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/myfaces-tobago.git


The following commit(s) were added to refs/heads/master by this push:
     new 12ba836  TOBAGO-1928 Required has no effect for tc:file
12ba836 is described below

commit 12ba836ee953bced82573a1902b15de35346baac
Author: Henning Noeth <hnoeth@apache.org>
AuthorDate: Mon Sep 17 16:57:24 2018 +0200

    TOBAGO-1928 Required has no effect for tc:file
    
    * required works for simple file upload
    * required must be implemented for multiple file upload (TOBAGO-1930)
---
 .../tobago/internal/renderkit/renderer/FileRenderer.java | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/FileRenderer.java
b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/FileRenderer.java
index 77867f6..e01226e 100644
--- a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/FileRenderer.java
+++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/FileRenderer.java
@@ -76,11 +76,12 @@ public class FileRenderer extends MessageLayoutRendererBase implements
Component
     }
 
     final AbstractUIFile file = (AbstractUIFile) component;
+    final boolean multiple = file.isMultiple() && !file.isRequired();
     final Object request = facesContext.getExternalContext().getRequest();
     if (request instanceof HttpServletRequest) {
       try {
         final HttpServletRequest httpServletRequest = (HttpServletRequest) request;
-        if (file.isMultiple()) {
+        if (multiple) {
           final List<Part> parts = new ArrayList<>();
           for (final Part part : httpServletRequest.getParts()) {
             if (file.getClientId(facesContext).equals(part.getName())) {
@@ -92,11 +93,14 @@ public class FileRenderer extends MessageLayoutRendererBase implements
Component
           }
         } else {
           final Part part = httpServletRequest.getPart(file.getClientId(facesContext));
+          final String submittedFileName = PartUtils.getSubmittedFileName(part);
           if (LOG.isDebugEnabled()) {
             LOG.debug("Uploaded file '{}', size={}, type='{}'",
-                PartUtils.getSubmittedFileName(part), part.getSize(), part.getContentType());
+                submittedFileName, part.getSize(), part.getContentType());
+          }
+          if (submittedFileName.length() > 0) {
+            file.setSubmittedValue(new HttpPartWrapper(part));
           }
-          file.setSubmittedValue(new HttpPartWrapper(part));
         }
       } catch (final Exception e) {
         LOG.error("", e);
@@ -116,6 +120,10 @@ public class FileRenderer extends MessageLayoutRendererBase implements
Component
     final String clientId = file.getClientId(facesContext);
     final String fieldId = file.getFieldId(facesContext);
     final String accept = createAcceptFromValidators(file);
+    final boolean multiple = file.isMultiple() && !file.isRequired();
+    if (file.isMultiple() && file.isRequired()) {
+      LOG.warn("Required multiple file upload is not supported."); //TODO TOBAGO-1930
+    }
 
     final TobagoResponseWriter writer = getResponseWriter(facesContext);
 
@@ -149,7 +157,7 @@ public class FileRenderer extends MessageLayoutRendererBase implements
Component
 
     // invisible file input
     writer.startElement(HtmlElements.INPUT);
-    writer.writeAttribute(HtmlAttributes.MULTIPLE, file.isMultiple());
+    writer.writeAttribute(HtmlAttributes.MULTIPLE, multiple);
     writer.writeAttribute(HtmlAttributes.TYPE, HtmlInputTypes.FILE);
     writer.writeAttribute(HtmlAttributes.ACCEPT, accept, true);
     writer.writeAttribute(HtmlAttributes.TABINDEX, -1);


Mime
View raw message