You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by dr...@apache.org on 2009/11/01 20:04:42 UTC
svn commit: r831729 - in /tapestry/tapestry5/trunk:
tapestry-core/src/main/java/org/apache/tapestry5/validator/
tapestry-core/src/main/resources/org/apache/tapestry5/
tapestry-core/src/test/java/org/apache/tapestry5/validator/
tapestry-ioc/src/main/jav...
Author: drobiazko
Date: Sun Nov 1 19:04:41 2009
New Revision: 831729
URL: http://svn.apache.org/viewvc?rev=831729&view=rev
Log:
TAP5-912: Validation of properties of type java.util.Collection should fail when the collection is empty
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/validator/Required.java
tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/tapestry.js
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/validator/RequiredTest.java
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/InternalUtils.java
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/validator/Required.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/validator/Required.java?rev=831729&r1=831728&r2=831729&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/validator/Required.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/validator/Required.java Sun Nov 1 19:04:41 2009
@@ -34,7 +34,7 @@
public void validate(Field field, Void constraintValue, MessageFormatter formatter, Object value)
throws ValidationException
{
- if (value == null || InternalUtils.isBlank(value.toString()))
+ if (value == null || InternalUtils.isEmptyCollection(value) || InternalUtils.isBlank(value.toString()))
throw new ValidationException(buildMessage(formatter, field));
}
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/tapestry.js
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/tapestry.js?rev=831729&r1=831728&r2=831729&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/tapestry.js (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/tapestry.js Sun Nov 1 19:04:41 2009
@@ -907,7 +907,7 @@
{
$(field).getFieldEventManager().requiredCheck = function(value)
{
- if (value.strip() == '')
+ if ((Object.isString(value) && value.strip() == '') || value == null)
$(field).showValidationMessage(message);
};
},
@@ -1299,7 +1299,7 @@
// Don't try to validate blank values; if the field is required, that error is already
// noted and presented to the user.
- if (!t.validationError && ! value.blank())
+ if (!t.validationError && ! (Object.isString(value) && value.blank()))
{
var translated = this.translator(value);
Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/validator/RequiredTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/validator/RequiredTest.java?rev=831729&r1=831728&r2=831729&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/validator/RequiredTest.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/validator/RequiredTest.java Sun Nov 1 19:04:41 2009
@@ -14,6 +14,8 @@
package org.apache.tapestry5.validator;
+import java.util.Arrays;
+
import org.apache.tapestry5.Field;
import org.apache.tapestry5.ValidationException;
import org.apache.tapestry5.ioc.MessageFormatter;
@@ -69,6 +71,42 @@
}
@Test
+ public void empty_collection_value()
+ {
+ MessageFormatter formatter = mockMessageFormatter();
+ Field field = mockFieldWithLabel("My Field");
+
+ train_format(formatter, "{message}", "My Field");
+
+ replay();
+
+ try
+ {
+ new Required().validate(field, null, formatter, Arrays.asList());
+ unreachable();
+ }
+ catch (ValidationException ex)
+ {
+ assertEquals(ex.getMessage(), "{message}");
+ }
+
+ verify();
+ }
+
+ @Test
+ public void not_empty_collection_value() throws Exception
+ {
+ MessageFormatter formatter = mockMessageFormatter();
+ Field field = mockField();
+
+ replay();
+
+ new Required().validate(field, null, formatter, Arrays.asList("A", "B"));
+
+ verify();
+ }
+
+ @Test
public void non_blank_value() throws Exception
{
MessageFormatter formatter = mockMessageFormatter();
Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/InternalUtils.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/InternalUtils.java?rev=831729&r1=831728&r2=831729&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/InternalUtils.java (original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/InternalUtils.java Sun Nov 1 19:04:41 2009
@@ -478,6 +478,21 @@
return input == null || input.length() == 0 || input.trim().length() == 0;
}
+
+ /**
+ * Returns true if the input is an empty collection.
+ */
+
+ public static boolean isEmptyCollection(Object input)
+ {
+ if(input instanceof Collection)
+ {
+ return ((Collection)input).isEmpty();
+ }
+
+ return false;
+ }
+
public static boolean isNonBlank(String input)
{
return !isBlank(input);