You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by iv...@apache.org on 2013/03/20 02:48:57 UTC

git commit: WICKET-5102

Updated Branches:
  refs/heads/master 0300c627e -> d110e3073


WICKET-5102


Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/d110e307
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/d110e307
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/d110e307

Branch: refs/heads/master
Commit: d110e30738cf3aac4dbd3a66fb5bd9f79e1880c6
Parents: 0300c62
Author: Igor Vaynberg <ig...@gmail.com>
Authored: Tue Mar 19 18:48:44 2013 -0700
Committer: Igor Vaynberg <ig...@gmail.com>
Committed: Tue Mar 19 18:48:54 2013 -0700

----------------------------------------------------------------------
 .../bean/validation/DefaultPropertyResolver.java   |   20 +++-
 .../validation/DefaultPropertyResolverTest.java    |   96 +++++++++++++++
 2 files changed, 113 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/d110e307/wicket-experimental/wicket-bean-validation/src/main/java/org/apache/wicket/bean/validation/DefaultPropertyResolver.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-bean-validation/src/main/java/org/apache/wicket/bean/validation/DefaultPropertyResolver.java b/wicket-experimental/wicket-bean-validation/src/main/java/org/apache/wicket/bean/validation/DefaultPropertyResolver.java
index 64caf18..91eb1a3 100644
--- a/wicket-experimental/wicket-bean-validation/src/main/java/org/apache/wicket/bean/validation/DefaultPropertyResolver.java
+++ b/wicket-experimental/wicket-bean-validation/src/main/java/org/apache/wicket/bean/validation/DefaultPropertyResolver.java
@@ -6,6 +6,7 @@ import java.lang.reflect.Method;
 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;
 
 /**
@@ -23,8 +24,21 @@ public class DefaultPropertyResolver implements IPropertyResolver
 	{
 		IModel<?> model = component.getModel();
 
-		if (!(model instanceof IPropertyReflectionAwareModel))
+		while (true)
 		{
+			if (model == null)
+			{
+				return null;
+			}
+			if (model instanceof IPropertyReflectionAwareModel)
+			{
+				break;
+			}
+			if (model instanceof IWrapModel<?>)
+			{
+				model = ((IWrapModel<?>)model).getWrappedModel();
+				continue;
+			}
 			return null;
 		}
 
@@ -35,11 +49,11 @@ public class DefaultPropertyResolver implements IPropertyResolver
 		{
 			return new Property(field.getDeclaringClass(), field.getName());
 		}
-	
+
 		Method getter = delegate.getPropertyGetter();
 		if (getter != null)
 		{
-			String name = getter.getName().substring(3, 1).toLowerCase() +
+			String name = getter.getName().substring(3, 4).toLowerCase() +
 				getter.getName().substring(4);
 			return new Property(getter.getDeclaringClass(), name);
 		}

http://git-wip-us.apache.org/repos/asf/wicket/blob/d110e307/wicket-experimental/wicket-bean-validation/src/test/java/org/apache/wicket/bean/validation/DefaultPropertyResolverTest.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-bean-validation/src/test/java/org/apache/wicket/bean/validation/DefaultPropertyResolverTest.java b/wicket-experimental/wicket-bean-validation/src/test/java/org/apache/wicket/bean/validation/DefaultPropertyResolverTest.java
new file mode 100644
index 0000000..227e3d3
--- /dev/null
+++ b/wicket-experimental/wicket-bean-validation/src/test/java/org/apache/wicket/bean/validation/DefaultPropertyResolverTest.java
@@ -0,0 +1,96 @@
+/*
+ * 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.wicket.bean.validation;
+
+import static org.hamcrest.CoreMatchers.*;
+import static org.junit.Assert.*;
+
+import org.apache.wicket.markup.html.form.TextField;
+import org.apache.wicket.model.PropertyModel;
+import org.apache.wicket.util.tester.WicketTesterScope;
+import org.junit.Rule;
+import org.junit.Test;
+
+public class DefaultPropertyResolverTest
+{
+	@Rule
+	public static WicketTesterScope scope = new WicketTesterScope();
+
+	public static class Bean1
+	{
+		private String foo;
+
+		public String getFoo()
+		{
+			return foo;
+		}
+	}
+
+	@Test
+	public void hasFieldAndGetter()
+	{
+		DefaultPropertyResolver resolver = new DefaultPropertyResolver();
+
+		TextField<?> component = new TextField<Bean1>("id", new PropertyModel<Bean1>(new Bean1(),
+			"foo"));
+		Property property = resolver.resolveProperty(component);
+		assertThat(property, not(nullValue()));
+		assertThat(property.getName(), is("foo"));
+		assertThat(property.getOwner().getName(), is(Bean1.class.getName()));
+	}
+
+	@Test
+	public void hasOnlyField()
+	{
+		DefaultPropertyResolver resolver = new DefaultPropertyResolver();
+
+		TextField<?> component = new TextField<Bean2>("id", new PropertyModel<Bean2>(new Bean2(),
+			"foo"));
+		Property property = resolver.resolveProperty(component);
+		assertThat(property, not(nullValue()));
+		assertThat(property.getName(), is("foo"));
+		assertThat(property.getOwner().getName(), is(Bean2.class.getName()));
+	}
+
+	public static class Bean2
+	{
+		private String foo;
+	}
+
+	@Test
+	public void hasOnlyGetter()
+	{
+		DefaultPropertyResolver resolver = new DefaultPropertyResolver();
+
+		TextField<?> component = new TextField<Bean3>("id", new PropertyModel<Bean3>(new Bean3(),
+			"foo"));
+		Property property = resolver.resolveProperty(component);
+		assertThat(property, not(nullValue()));
+		assertThat(property.getName(), is("foo"));
+		assertThat(property.getOwner().getName(), is(Bean3.class.getName()));
+	}
+
+
+	public static class Bean3
+	{
+		public String getFoo()
+		{
+			return "foo";
+		}
+	}
+
+}