You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by mg...@apache.org on 2015/04/29 14:04:56 UTC
wicket git commit: WICKET-5897 Use the #isEnabled() method with
validators
Repository: wicket
Updated Branches:
refs/heads/master 43ef1fad7 -> 928fb37f8
WICKET-5897 Use the #isEnabled() method with validators
Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/928fb37f
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/928fb37f
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/928fb37f
Branch: refs/heads/master
Commit: 928fb37f82a0b231ca2dc0de5fed1c48e89a83d8
Parents: 43ef1fa
Author: Martin Tzvetanov Grigorov <mg...@apache.org>
Authored: Wed Apr 29 15:04:30 2015 +0300
Committer: Martin Tzvetanov Grigorov <mg...@apache.org>
Committed: Wed Apr 29 15:04:30 2015 +0300
----------------------------------------------------------------------
.../wicket/markup/html/form/FormComponent.java | 7 +++-
.../validation/ValidatorBehaviorTest.java | 43 +++++++++++++++++++-
2 files changed, 47 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/wicket/blob/928fb37f/wicket-core/src/main/java/org/apache/wicket/markup/html/form/FormComponent.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/markup/html/form/FormComponent.java b/wicket-core/src/main/java/org/apache/wicket/markup/html/form/FormComponent.java
index c0f4f10..32f720d 100644
--- a/wicket-core/src/main/java/org/apache/wicket/markup/html/form/FormComponent.java
+++ b/wicket-core/src/main/java/org/apache/wicket/markup/html/form/FormComponent.java
@@ -1498,10 +1498,15 @@ public abstract class FormComponent<T> extends LabeledWebMarkupContainer impleme
boolean isNull = getConvertedInput() == null;
- IValidator<T> validator = null;
+ IValidator<T> validator;
for (Behavior behavior : getBehaviors())
{
+ if (isBehaviorAccepted(behavior) == false)
+ {
+ continue;
+ }
+
validator = null;
if (behavior instanceof ValidatorAdapter)
{
http://git-wip-us.apache.org/repos/asf/wicket/blob/928fb37f/wicket-core/src/test/java/org/apache/wicket/validation/ValidatorBehaviorTest.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/java/org/apache/wicket/validation/ValidatorBehaviorTest.java b/wicket-core/src/test/java/org/apache/wicket/validation/ValidatorBehaviorTest.java
index 81dcad4..05d2b46 100644
--- a/wicket-core/src/test/java/org/apache/wicket/validation/ValidatorBehaviorTest.java
+++ b/wicket-core/src/test/java/org/apache/wicket/validation/ValidatorBehaviorTest.java
@@ -61,6 +61,28 @@ public class ValidatorBehaviorTest extends WicketTestCase
assertFalse(tester.getLastResponseAsString().contains("foo=\"bar\""));
}
+
+ /**
+ * Tests that disabled validators are not used
+ * https://issues.apache.org/jira/browse/WICKET-5897
+ */
+ @Test
+ public void disabledValidator()
+ {
+ TestPage page = new TestPage();
+ page.name.add(new DisabledValidator());
+
+ tester.startPage(page);
+ assertTrue(page.name.isValid());
+
+ FormTester ft = tester.newFormTester("form");
+ ft.setValue("name", "22");
+ ft.submit();
+
+ assertTrue(page.name.isValid());
+ }
+
+
/**
* Tests validators are treated as validators
*/
@@ -170,9 +192,7 @@ public class ValidatorBehaviorTest extends WicketTestCase
error.setMessage("MINIMUM");
validatable.error(error);
}
-
}
-
}
/**
@@ -201,4 +221,23 @@ public class ValidatorBehaviorTest extends WicketTestCase
"<form wicket:id='form'><input wicket:id='name' type='text'/></form>");
}
}
+
+ public static class DisabledValidator extends Behavior implements IValidator<String>
+ {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public void validate(IValidatable<String> validatable)
+ {
+ ValidationError error = new ValidationError();
+ error.setMessage("validate() method should not be executed");
+ validatable.error(error);
+ }
+
+ @Override
+ public boolean isEnabled(Component component)
+ {
+ return false;
+ }
+ }
}