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 2014/09/22 22:51:49 UTC
[1/2] git commit: WICKET-5692: improved Unresolvable Property Message
Repository: wicket
Updated Branches:
refs/heads/wicket-6.x 6b906d53a -> 49aaea831
WICKET-5692: improved Unresolvable Property Message
(cherry picked from commit 09fc316b768968f99c2a80bda1dbaee7a596eb12)
Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/fe66a383
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/fe66a383
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/fe66a383
Branch: refs/heads/wicket-6.x
Commit: fe66a3836f87c7a98eb48a1c7432d4c7160036f3
Parents: 6b906d5
Author: Thibault Kruse <th...@comsysto.com>
Authored: Mon Sep 22 22:08:19 2014 +0200
Committer: Martin Tzvetanov Grigorov <mg...@apache.org>
Committed: Mon Sep 22 22:49:07 2014 +0200
----------------------------------------------------------------------
.../bean/validation/PropertyValidator.java | 44 +++++++++++++++++---
.../PropertyValidatorRequiredTest.java | 24 +++++++++--
2 files changed, 59 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/wicket/blob/fe66a383/wicket-bean-validation/src/main/java/org/apache/wicket/bean/validation/PropertyValidator.java
----------------------------------------------------------------------
diff --git a/wicket-bean-validation/src/main/java/org/apache/wicket/bean/validation/PropertyValidator.java b/wicket-bean-validation/src/main/java/org/apache/wicket/bean/validation/PropertyValidator.java
index a2486c7..17aa38f 100644
--- a/wicket-bean-validation/src/main/java/org/apache/wicket/bean/validation/PropertyValidator.java
+++ b/wicket-bean-validation/src/main/java/org/apache/wicket/bean/validation/PropertyValidator.java
@@ -18,6 +18,8 @@ import org.apache.wicket.behavior.Behavior;
import org.apache.wicket.markup.ComponentTag;
import org.apache.wicket.markup.html.form.FormComponent;
import org.apache.wicket.model.IModel;
+import org.apache.wicket.model.IPropertyReflectionAwareModel;
+import org.apache.wicket.model.IWrapModel;
import org.apache.wicket.model.PropertyModel;
import org.apache.wicket.validation.IValidatable;
import org.apache.wicket.validation.IValidator;
@@ -93,18 +95,48 @@ public class PropertyValidator<T> extends Behavior implements IValidator<T>
this.groups_ = groups;
}
+ /**
+ * To support debugging, trying to provide useful information where possible
+ * @return
+ */
+ private String createUnresolvablePropertyMessage(FormComponent<T> component) {
+ String baseMessage = "Could not resolve Bean Property from component: " + component
+ + ". (Hints:) Possible causes are a typo in the PropertyExpression, a null reference or a model that does not work in combination with a "
+ + IPropertyResolver.class.getSimpleName() + ".";
+
+ IModel<?> model = component.getModel();
+ // Code sadly copied over from DefaultPropertyResolver
+ while (true)
+ {
+ if (model == null)
+ {
+ break;
+ }
+ if (model instanceof IPropertyReflectionAwareModel)
+ {
+ break;
+ }
+ if (model instanceof IWrapModel<?>)
+ {
+ model = ((IWrapModel<?>)model).getWrappedModel();
+ continue;
+ }
+ }
+ if (model != null) {
+ baseMessage += " Model : " + model;
+ }
+ return baseMessage;
+ }
+
private Property getProperty()
{
if (property_ == null)
{
- property_ = BeanValidationConfiguration.get().resolveProperty(component);
+ BeanValidationContext config = BeanValidationConfiguration.get();
+ property_ = config.resolveProperty(component);
if (property_ == null)
{
- throw new IllegalStateException(
- "Could not resolve Property from component: " + component
- + ". Either specify the Property in the constructor or use a model that works in combination with a "
- + IPropertyResolver.class.getSimpleName()
- + " to resolve the Property automatically");
+ throw new IllegalStateException(createUnresolvablePropertyMessage(component));
}
}
return property_;
http://git-wip-us.apache.org/repos/asf/wicket/blob/fe66a383/wicket-bean-validation/src/test/java/org/apache/wicket/bean/validation/PropertyValidatorRequiredTest.java
----------------------------------------------------------------------
diff --git a/wicket-bean-validation/src/test/java/org/apache/wicket/bean/validation/PropertyValidatorRequiredTest.java b/wicket-bean-validation/src/test/java/org/apache/wicket/bean/validation/PropertyValidatorRequiredTest.java
index 4b0ebd6..69186e4 100644
--- a/wicket-bean-validation/src/test/java/org/apache/wicket/bean/validation/PropertyValidatorRequiredTest.java
+++ b/wicket-bean-validation/src/test/java/org/apache/wicket/bean/validation/PropertyValidatorRequiredTest.java
@@ -3,6 +3,10 @@ package org.apache.wicket.bean.validation;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
+import java.util.Arrays;
+import java.util.List;
+
+import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import org.apache.wicket.MarkupContainer;
@@ -66,6 +70,8 @@ public class PropertyValidatorRequiredTest
assertFalse(page.input19.isRequired());
assertFalse(page.input20.isRequired());
+ assertTrue(page.input21.isRequired());
+
}
/**
@@ -101,7 +107,7 @@ public class PropertyValidatorRequiredTest
private TestBean bean = new TestBean();
private FormComponent<String> input1, input2, input3, input4, input5, input6, input7,
input8, input9, input10, input11, input12, input13, input14, input15, input16, input17,
- input18, input19, input20;
+ input18, input19, input20, input21;
public TestPage()
{
@@ -156,9 +162,12 @@ public class PropertyValidatorRequiredTest
input20 = new TextField<String>("input20", new PropertyModel<String>(this,
"bean.propertyOneTwo")).add(new PropertyValidator<String>(GroupThree.class));
+ input21 = new TextField<String>("input21", new PropertyModel<String>(this,
+ "bean.subBeanList[0].property")).add(new PropertyValidator<>());
+
form.add(input1, input2, input3, input4, input5, input6, input7, input8, input9,
input10, input11, input12, input13, input14, input15, input16, input17, input18,
- input19, input20);
+ input19, input20, input21);
}
@@ -167,7 +176,7 @@ public class PropertyValidatorRequiredTest
Class<?> containerClass)
{
return new StringResourceStream(
- "<form wicket:id='form'><input wicket:id='input1'/><input wicket:id='input2'/><input wicket:id='input3'/><input wicket:id='input4'/><input wicket:id='input5'/><input wicket:id='input6'/><input wicket:id='input7'/><input wicket:id='input8'/><input wicket:id='input9'/><input wicket:id='input10'/><input wicket:id='input11'/><input wicket:id='input12'/><input wicket:id='input13'/><input wicket:id='input14'/><input wicket:id='input15'/><input wicket:id='input16'/><input wicket:id='input17'/><input wicket:id='input18'/><input wicket:id='input19'/><input wicket:id='input20'/></form>");
+ "<form wicket:id='form'><input wicket:id='input1'/><input wicket:id='input2'/><input wicket:id='input3'/><input wicket:id='input4'/><input wicket:id='input5'/><input wicket:id='input6'/><input wicket:id='input7'/><input wicket:id='input8'/><input wicket:id='input9'/><input wicket:id='input10'/><input wicket:id='input11'/><input wicket:id='input12'/><input wicket:id='input13'/><input wicket:id='input14'/><input wicket:id='input15'/><input wicket:id='input16'/><input wicket:id='input17'/><input wicket:id='input18'/><input wicket:id='input19'/><input wicket:id='input20'/><input wicket:id='input21'/></form>");
}
}
@@ -184,8 +193,17 @@ public class PropertyValidatorRequiredTest
{
}
+ public static class TestContainedBean {
+ @NotNull
+ String property;
+ }
+
public static class TestBean
{
+ @Valid
+ @NotNull
+ List<TestContainedBean> subBeanList = Arrays.asList(new TestContainedBean());
+
@NotNull
String property;
[2/2] git commit: Java 6 no-diamonds
Posted by mg...@apache.org.
Java 6 no-diamonds
Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/49aaea83
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/49aaea83
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/49aaea83
Branch: refs/heads/wicket-6.x
Commit: 49aaea8313fb2079e90579e434e6239e21ee652b
Parents: fe66a38
Author: Martin Tzvetanov Grigorov <mg...@apache.org>
Authored: Mon Sep 22 22:51:20 2014 +0200
Committer: Martin Tzvetanov Grigorov <mg...@apache.org>
Committed: Mon Sep 22 22:51:20 2014 +0200
----------------------------------------------------------------------
.../wicket/bean/validation/PropertyValidatorRequiredTest.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/wicket/blob/49aaea83/wicket-bean-validation/src/test/java/org/apache/wicket/bean/validation/PropertyValidatorRequiredTest.java
----------------------------------------------------------------------
diff --git a/wicket-bean-validation/src/test/java/org/apache/wicket/bean/validation/PropertyValidatorRequiredTest.java b/wicket-bean-validation/src/test/java/org/apache/wicket/bean/validation/PropertyValidatorRequiredTest.java
index 69186e4..e17c4bb 100644
--- a/wicket-bean-validation/src/test/java/org/apache/wicket/bean/validation/PropertyValidatorRequiredTest.java
+++ b/wicket-bean-validation/src/test/java/org/apache/wicket/bean/validation/PropertyValidatorRequiredTest.java
@@ -163,7 +163,7 @@ public class PropertyValidatorRequiredTest
"bean.propertyOneTwo")).add(new PropertyValidator<String>(GroupThree.class));
input21 = new TextField<String>("input21", new PropertyModel<String>(this,
- "bean.subBeanList[0].property")).add(new PropertyValidator<>());
+ "bean.subBeanList[0].property")).add(new PropertyValidator<String>());
form.add(input1, input2, input3, input4, input5, input6, input7, input8, input9,
input10, input11, input12, input13, input14, input15, input16, input17, input18,