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/08/17 07:21:07 UTC
svn commit: r1756582 - in /myfaces/tobago/branches/tobago-2.0.x: ./
tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/
tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/
tobago-core/src/main/java/org/apa...
Author: lofwyr
Date: Wed Aug 17 07:21:07 2016
New Revision: 1756582
URL: http://svn.apache.org/viewvc?rev=1756582&view=rev
Log:
TOBAGO-1580: Multifile-Upload Component
Added:
myfaces/tobago/branches/tobago-2.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/declaration/IsMultiple.java
Modified:
myfaces/tobago/branches/tobago-2.0.x/pom.xml
myfaces/tobago/branches/tobago-2.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUIFile.java
myfaces/tobago/branches/tobago-2.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/FileTagDeclaration.java
myfaces/tobago/branches/tobago-2.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/extension/FileExtensionTag.java
myfaces/tobago/branches/tobago-2.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/webapp/TobagoMultipartFormdataRequest.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/FileRenderer.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.js
Modified: myfaces/tobago/branches/tobago-2.0.x/pom.xml
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-2.0.x/pom.xml?rev=1756582&r1=1756581&r2=1756582&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-2.0.x/pom.xml (original)
+++ myfaces/tobago/branches/tobago-2.0.x/pom.xml Wed Aug 17 07:21:07 2016
@@ -456,7 +456,7 @@
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
- <version>1.3.1</version>
+ <version>1.3.2</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
Modified: myfaces/tobago/branches/tobago-2.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUIFile.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/AbstractUIFile.java?rev=1756582&r1=1756581&r2=1756582&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-2.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUIFile.java (original)
+++ myfaces/tobago/branches/tobago-2.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUIFile.java Wed Aug 17 07:21:07 2016
@@ -55,5 +55,7 @@ public abstract class AbstractUIFile ext
public abstract boolean isReadonly();
+ public abstract boolean isMultiple();
+
public abstract Integer getTabIndex();
}
Modified: myfaces/tobago/branches/tobago-2.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/FileTagDeclaration.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-2.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/FileTagDeclaration.java?rev=1756582&r1=1756581&r2=1756582&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-2.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/FileTagDeclaration.java (original)
+++ myfaces/tobago/branches/tobago-2.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/FileTagDeclaration.java Wed Aug 17 07:21:07 2016
@@ -42,6 +42,7 @@ import org.apache.myfaces.tobago.interna
import org.apache.myfaces.tobago.internal.taglib.declaration.IsGridLayoutComponent;
import org.apache.myfaces.tobago.internal.taglib.declaration.IsReadonly;
import org.apache.myfaces.tobago.internal.taglib.declaration.IsRequired;
+import org.apache.myfaces.tobago.internal.taglib.declaration.IsMultiple;
import javax.faces.component.UIInput;
@@ -64,7 +65,7 @@ import javax.faces.component.UIInput;
allowedChildComponenents = "NONE")
public interface FileTagDeclaration
extends HasValidator, HasValidatorMessage, HasRequiredMessage, HasConverterMessage, HasOnchange,
- HasValueChangeListener, HasIdBindingAndRendered, IsDisabled, HasMarkup, HasCurrentMarkup, IsFocus,
+ HasValueChangeListener, HasIdBindingAndRendered, IsDisabled, HasMarkup, HasCurrentMarkup, IsFocus, IsMultiple,
HasLabel, HasTip, IsReadonly, IsRequired, HasTabIndex, IsGridLayoutComponent {
/**
@@ -74,7 +75,7 @@ public interface FileTagDeclaration
*/
@TagAttribute()
@UIComponentTagAttribute(
- type = { "org.apache.commons.fileupload.FileItem" },
+ type = { "org.apache.commons.fileupload.FileItem", "org.apache.commons.fileupload.FileItem[]" },
expression = DynamicExpression.VALUE_EXPRESSION_REQUIRED)
void setValue(String value);
}
Added: myfaces/tobago/branches/tobago-2.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/declaration/IsMultiple.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-2.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/declaration/IsMultiple.java?rev=1756582&view=auto
==============================================================================
--- myfaces/tobago/branches/tobago-2.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/declaration/IsMultiple.java (added)
+++ myfaces/tobago/branches/tobago-2.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/declaration/IsMultiple.java Wed Aug 17 07:21:07 2016
@@ -0,0 +1,30 @@
+/*
+ * 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.tobago.internal.taglib.declaration;
+
+import org.apache.myfaces.tobago.apt.annotation.TagAttribute;
+import org.apache.myfaces.tobago.apt.annotation.UIComponentTagAttribute;
+
+public interface IsMultiple {
+
+ @TagAttribute
+ @UIComponentTagAttribute(type = "boolean", defaultValue = "false")
+ void setMultiple(String multiple);
+}
Modified: myfaces/tobago/branches/tobago-2.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/extension/FileExtensionTag.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-2.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/extension/FileExtensionTag.java?rev=1756582&r1=1756581&r2=1756582&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-2.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/extension/FileExtensionTag.java (original)
+++ myfaces/tobago/branches/tobago-2.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/extension/FileExtensionTag.java Wed Aug 17 07:21:07 2016
@@ -62,6 +62,7 @@ public class FileExtensionTag extends To
private MethodExpression validator;
private ValueExpression disabled;
private ValueExpression rendered;
+ private ValueExpression multiple;
private ValueExpression tip;
private ValueExpression onchange;
private ValueExpression labelWidth;
@@ -120,6 +121,9 @@ public class FileExtensionTag extends To
if (disabled != null) {
fileTag.setDisabled(disabled);
}
+ if (multiple != null) {
+ fileTag.setDisabled(multiple);
+ }
if (fieldId != null) {
fileTag.setId(fieldId);
}
@@ -167,6 +171,7 @@ public class FileExtensionTag extends To
binding = null;
validator = null;
disabled = null;
+ multiple = null;
label = null;
accessKey = null;
labelWidth = null;
@@ -284,6 +289,15 @@ public class FileExtensionTag extends To
}
/**
+ * Flag indicating that this element is for multiple files.
+ */
+ @TagAttribute()
+ @UIComponentTagAttribute(type = "boolean", defaultValue = "false")
+ public void setMultiple(final ValueExpression multiple) {
+ this.multiple = multiple;
+ }
+
+ /**
* Text value to display as tooltip.
*/
@TagAttribute
Modified: myfaces/tobago/branches/tobago-2.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/webapp/TobagoMultipartFormdataRequest.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-2.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/webapp/TobagoMultipartFormdataRequest.java?rev=1756582&r1=1756581&r2=1756582&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-2.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/webapp/TobagoMultipartFormdataRequest.java (original)
+++ myfaces/tobago/branches/tobago-2.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/webapp/TobagoMultipartFormdataRequest.java Wed Aug 17 07:21:07 2016
@@ -23,15 +23,16 @@ import org.apache.commons.fileupload.Fil
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
+import org.apache.myfaces.tobago.internal.component.AbstractUIPage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.apache.myfaces.tobago.internal.component.AbstractUIPage;
import javax.faces.FacesException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
import java.io.File;
import java.io.UnsupportedEncodingException;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Enumeration;
@@ -50,7 +51,7 @@ public class TobagoMultipartFormdataRequ
private Map<String, String[]> parameters;
- private Map<String, FileItem> fileItems;
+ private Map<String, List<FileItem>> fileItems;
public TobagoMultipartFormdataRequest(final HttpServletRequest request) {
this(request, System.getProperty("java.io.tmpdir"), ONE_MB);
@@ -69,7 +70,7 @@ public class TobagoMultipartFormdataRequ
throw new FacesException(errorText);
} else {
parameters = new HashMap<String, String[]>();
- fileItems = new HashMap<String, FileItem>();
+ fileItems = new HashMap<String, List<FileItem>>();
final DiskFileItemFactory factory = new DiskFileItemFactory();
factory.setRepository(new File(repositoryPath));
@@ -114,7 +115,12 @@ public class TobagoMultipartFormdataRequ
addParameter(key, newValue);
} else {
- fileItems.put(key, item);
+ List<FileItem> help = this.fileItems.get(key);
+ if (help == null) {
+ help = new ArrayList<FileItem>();
+ this.fileItems.put(key, help);
+ }
+ help.add(item);
}
}
@@ -148,7 +154,20 @@ public class TobagoMultipartFormdataRequ
public FileItem getFileItem(final String key) {
if (fileItems != null) {
- return fileItems.get(key);
+ final List<FileItem> fileItems = this.fileItems.get(key);
+ if (fileItems.size() > 0) {
+ return fileItems.get(0);
+ } else {
+ return null;
+ }
+ }
+ return null;
+ }
+
+ public FileItem[] getFileItems(final String key) {
+ if (fileItems != null) {
+ final List<FileItem> fileItems = this.fileItems.get(key);
+ return fileItems.toArray(new FileItem[fileItems.size()]);
}
return null;
}
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=1756582&r1=1756581&r2=1756582&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 Aug 17 07:21:07 2016
@@ -32,15 +32,23 @@ public class Upload {
private FileItem file1;
private FileItem file2;
+ private FileItem[] fileMulti;
private List<UploadItem> list = new ArrayList<UploadItem>();
public String upload() {
upload(file1);
upload(file2);
+ upload(fileMulti);
return null;
}
+ public void upload(FileItem[] files) {
+ for (FileItem file : files) {
+ upload(file);
+ }
+ }
+
public void upload(FileItem file) {
LOG.info("checking file item");
if (file == null || file.get().length == 0) {
@@ -75,6 +83,14 @@ public class Upload {
this.file2 = file2;
}
+ public FileItem[] getFileMulti() {
+ return fileMulti;
+ }
+
+ public void setFileMulti(FileItem[] fileMulti) {
+ this.fileMulti = fileMulti;
+ }
+
public List<UploadItem> getList() {
return list;
}
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=1756582&r1=1756581&r2=1756582&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 Aug 17 07:21:07 2016
@@ -41,6 +41,10 @@
<tc:validateFileItem contentType="image/*"/>
</tx:file>
<tc:panel/>
+
+ <tx:file multiple="true" label="Upload multiple:" value="#{upload.fileMulti}" tip="multiple files"/>
+ <tc:panel/>
+
</tc:panel>
<tc:sheet var="entry" value="#{upload.list}" columns="*;*;*">
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/FileRenderer.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/FileRenderer.java?rev=1756582&r1=1756581&r2=1756582&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/FileRenderer.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/FileRenderer.java Wed Aug 17 07:21:07 2016
@@ -81,13 +81,23 @@ public class FileRenderer extends InputR
+ "See documentation for <tc:file>");
} else {
- final FileItem item = request.getFileItem(input.getClientId(facesContext));
-
- if (LOG.isDebugEnabled()) {
- LOG.debug("Uploaded file name : \"" + item.getName()
- + "\" size = " + item.getSize());
+ if (input.isMultiple()) {
+ final FileItem[] items = request.getFileItems(input.getClientId(facesContext));
+ if (LOG.isDebugEnabled()) {
+ for (FileItem item : items) {
+ LOG.debug("Uploaded file name : \"" + item.getName()
+ + "\" size = " + item.getSize());
+ }
+ }
+ input.setSubmittedValue(items);
+ } else {
+ final FileItem item = request.getFileItem(input.getClientId(facesContext));
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Uploaded file name : \"" + item.getName()
+ + "\" size = " + item.getSize());
+ }
+ input.setSubmittedValue(item);
}
- input.setSubmittedValue(item);
//TODO remove this
input.setValid(true);
}
@@ -123,6 +133,7 @@ public class FileRenderer extends InputR
// invisible file input
writer.startElement(HtmlElements.INPUT, file);
+ writer.writeAttribute(HtmlAttributes.MULTIPLE, file.isMultiple());
writer.writeIdAttribute(clientId + ComponentUtils.SUB_SEPARATOR + "real");
writer.writeAttribute(HtmlAttributes.TYPE, HtmlInputTypes.FILE, false);
writer.writeClassAttribute(Classes.create(file, "real"));
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.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.js?rev=1756582&r1=1756581&r2=1756582&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.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.js Wed Aug 17 07:21:07 2016
@@ -2754,13 +2754,18 @@ Tobago.File.init = function(elements) {
files.change(function () {
var file = jQuery(this);
var pretty = file.prev();
- var filename = file.val();
- // remove path, if any. Some old browsers set the path, others like webkit uses the prefix "C:\facepath\".
- var pos = Math.max(filename.lastIndexOf('/'), filename.lastIndexOf('\\'));
- if (pos >= 0) {
- filename = filename.substr(pos + 1);
+ var text;
+ if (file.prop("multiple")) {
+ text = file.prop("files").length + " files"; // todo i18n
+ } else {
+ text = file.val();
+ // remove path, if any. Some old browsers set the path, others like webkit uses the prefix "C:\facepath\".
+ var pos = Math.max(text.lastIndexOf('/'), text.lastIndexOf('\\'));
+ if (pos >= 0) {
+ text = text.substr(pos + 1);
+ }
}
- pretty.val(filename);
+ pretty.val(text);
});
if (files.length > 0) {
jQuery("form").attr('enctype', 'multipart/form-data')