You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by ad...@apache.org on 2014/09/04 15:42:54 UTC
[1/3] git commit: WICKET-5691 Wicket FileUploadField.getFileUploads()
should never return null.
Repository: wicket
Updated Branches:
refs/heads/wicket-6.x 2e729ab1b -> c66448712
WICKET-5691 Wicket FileUploadField.getFileUploads() should never return
null.
Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/d14ee451
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/d14ee451
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/d14ee451
Branch: refs/heads/wicket-6.x
Commit: d14ee4515208d2c6820957aa5b9a2afaa5c953dd
Parents: 2e729ab
Author: adelbene <an...@gmail.com>
Authored: Wed Sep 3 22:39:38 2014 +0200
Committer: adelbene <an...@gmail.com>
Committed: Thu Sep 4 15:31:42 2014 +0200
----------------------------------------------------------------------
.../html/form/upload/FileUploadField.java | 9 +++---
.../html/form/upload/FileUploadFieldTest.java | 32 +++++++++++++++++---
2 files changed, 32 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/wicket/blob/d14ee451/wicket-core/src/main/java/org/apache/wicket/markup/html/form/upload/FileUploadField.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/markup/html/form/upload/FileUploadField.java b/wicket-core/src/main/java/org/apache/wicket/markup/html/form/upload/FileUploadField.java
index bfd6059..89c5913 100644
--- a/wicket-core/src/main/java/org/apache/wicket/markup/html/form/upload/FileUploadField.java
+++ b/wicket-core/src/main/java/org/apache/wicket/markup/html/form/upload/FileUploadField.java
@@ -81,7 +81,7 @@ public class FileUploadField extends FormComponent<List<FileUpload>>
}
/**
- * @return a list of all uploaded files. It will return more than one files if:
+ * @return a list of all uploaded files. The list is empty if no files were selected. It will return more than one files if:
* <ul>
* <li>HTML5 <input type="file" <strong>multiple</strong> /> is used</li>
* <li>the browser supports <em>multiple</em> attribute</li>
@@ -95,6 +95,8 @@ public class FileUploadField extends FormComponent<List<FileUpload>>
return fileUploads;
}
+ fileUploads = new ArrayList<FileUpload>();
+
// Get request
final Request request = getRequest();
@@ -112,15 +114,12 @@ public class FileUploadField extends FormComponent<List<FileUpload>>
// bytes)
if (item != null && item.getSize() > 0)
{
- if (fileUploads == null)
- {
- fileUploads = new ArrayList<FileUpload>();
- }
fileUploads.add(new FileUpload(item));
}
}
}
}
+
return fileUploads;
}
http://git-wip-us.apache.org/repos/asf/wicket/blob/d14ee451/wicket-core/src/test/java/org/apache/wicket/markup/html/form/upload/FileUploadFieldTest.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/java/org/apache/wicket/markup/html/form/upload/FileUploadFieldTest.java b/wicket-core/src/test/java/org/apache/wicket/markup/html/form/upload/FileUploadFieldTest.java
index 203db1e..a9f6c51 100644
--- a/wicket-core/src/test/java/org/apache/wicket/markup/html/form/upload/FileUploadFieldTest.java
+++ b/wicket-core/src/test/java/org/apache/wicket/markup/html/form/upload/FileUploadFieldTest.java
@@ -108,7 +108,7 @@ public class FileUploadFieldTest extends WicketTestCase
}
}
}
-
+
/**
* @throws IOException
*/
@@ -126,7 +126,24 @@ public class FileUploadFieldTest extends WicketTestCase
assertFalse(page.getForm().hasError());
}
- /** */
+ /**
+ * https://issues.apache.org/jira/browse/WICKET-5691
+ *
+ * */
+ @Test
+ public void testEmptyField() throws Exception
+ {
+ tester.startPage(TestValidationPage.class);
+
+ FormTester formtester = tester.newFormTester("form");
+ formtester.submit();
+
+ FileUploadField fileUploadField = (FileUploadField)tester.getComponentFromLastRenderedPage("form:upload");
+
+ assertEquals(0, fileUploadField.getFileUploads().size());
+ }
+
+
public static class TestValidationPage extends MockPageWithFormAndUploadField
{
/** */
@@ -147,11 +164,18 @@ public class FileUploadFieldTest extends WicketTestCase
@Override
public void validate(IValidatable<List<FileUpload>> validatable)
{
- if (validatable.getValue() instanceof List == false)
+ List<FileUpload> fieldValue = validatable.getValue();
+
+ if (fieldValue.size() == 0)
+ {
+ return;
+ }
+
+ if (fieldValue instanceof List == false)
{
validatable.error(new ValidationError().addKey("validatable value type not expected"));
}
- FileUpload upload = validatable.getValue().get(0);
+ FileUpload upload = fieldValue.get(0);
if (!upload.getClientFileName().contains(TEST_FILE_NAME))
{
validatable.error(new ValidationError().addKey("uploaded file name not expected"));
[3/3] git commit: Removed diamond <>
Posted by ad...@apache.org.
Removed diamond <>
Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/c6644871
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/c6644871
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/c6644871
Branch: refs/heads/wicket-6.x
Commit: c66448712d7f247b3f89993121c3796a5d8b3a49
Parents: 0da61ba
Author: adelbene <an...@gmail.com>
Authored: Thu Sep 4 15:41:54 2014 +0200
Committer: adelbene <an...@gmail.com>
Committed: Thu Sep 4 15:41:54 2014 +0200
----------------------------------------------------------------------
.../apache/wicket/markup/html/form/upload/FileUploadField.java | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/wicket/blob/c6644871/wicket-core/src/main/java/org/apache/wicket/markup/html/form/upload/FileUploadField.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/markup/html/form/upload/FileUploadField.java b/wicket-core/src/main/java/org/apache/wicket/markup/html/form/upload/FileUploadField.java
index 40a22a0..4c2c2e8 100644
--- a/wicket-core/src/main/java/org/apache/wicket/markup/html/form/upload/FileUploadField.java
+++ b/wicket-core/src/main/java/org/apache/wicket/markup/html/form/upload/FileUploadField.java
@@ -95,7 +95,7 @@ public class FileUploadField extends FormComponent<List<FileUpload>>
return fileUploads;
}
- fileUploads = new ArrayList<>();
+ fileUploads = new ArrayList<FileUpload>();
// Get request
final Request request = getRequest();
@@ -144,7 +144,7 @@ public class FileUploadField extends FormComponent<List<FileUpload>>
List<FileUpload> fileUploads = getFileUploads();
if (fileUploads.isEmpty() == false)
{
- List<String> clientFileNames = new ArrayList<>();
+ List<String> clientFileNames = new ArrayList<String>();
for (FileUpload fu : fileUploads)
{
clientFileNames.add(fu.getClientFileName());
[2/3] git commit: WICKET-5691 Wicket FileUploadField.getFileUploads()
should never return null.
Posted by ad...@apache.org.
WICKET-5691 Wicket FileUploadField.getFileUploads() should never return null.
Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/0da61bac
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/0da61bac
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/0da61bac
Branch: refs/heads/wicket-6.x
Commit: 0da61bac1ce17a4b1723027042e61cb0c4b0ac9d
Parents: d14ee45
Author: Martin Tzvetanov Grigorov <mg...@apache.org>
Authored: Thu Sep 4 09:18:44 2014 +0300
Committer: adelbene <an...@gmail.com>
Committed: Thu Sep 4 15:37:02 2014 +0200
----------------------------------------------------------------------
.../wicket/markup/html/form/upload/FileUploadField.java | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/wicket/blob/0da61bac/wicket-core/src/main/java/org/apache/wicket/markup/html/form/upload/FileUploadField.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/markup/html/form/upload/FileUploadField.java b/wicket-core/src/main/java/org/apache/wicket/markup/html/form/upload/FileUploadField.java
index 89c5913..40a22a0 100644
--- a/wicket-core/src/main/java/org/apache/wicket/markup/html/form/upload/FileUploadField.java
+++ b/wicket-core/src/main/java/org/apache/wicket/markup/html/form/upload/FileUploadField.java
@@ -77,7 +77,7 @@ public class FileUploadField extends FormComponent<List<FileUpload>>
{
List<FileUpload> fileUploads = getFileUploads();
- return (fileUploads != null && !fileUploads.isEmpty()) ? fileUploads.get(0) : null;
+ return fileUploads.isEmpty() ? null : fileUploads.get(0) ;
}
/**
@@ -95,7 +95,7 @@ public class FileUploadField extends FormComponent<List<FileUpload>>
return fileUploads;
}
- fileUploads = new ArrayList<FileUpload>();
+ fileUploads = new ArrayList<>();
// Get request
final Request request = getRequest();
@@ -142,9 +142,9 @@ public class FileUploadField extends FormComponent<List<FileUpload>>
public String[] getInputAsArray()
{
List<FileUpload> fileUploads = getFileUploads();
- if (fileUploads != null)
+ if (fileUploads.isEmpty() == false)
{
- List<String> clientFileNames = new ArrayList<String>();
+ List<String> clientFileNames = new ArrayList<>();
for (FileUpload fu : fileUploads)
{
clientFileNames.add(fu.getClientFileName());