You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by jc...@apache.org on 2008/02/06 11:50:07 UTC

svn commit: r618954 - in /wicket/trunk/jdk-1.4/wicket/src: main/java/org/apache/wicket/markup/html/form/ main/java/org/apache/wicket/model/ test/java/org/apache/wicket/util/lang/

Author: jcompagner
Date: Wed Feb  6 02:50:05 2008
New Revision: 618954

URL: http://svn.apache.org/viewvc?rev=618954&view=rev
Log:
fix for getting the resolving the class from an expression, no more exception is thrown but a warning is logged

Added:
    wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/util/lang/Country2.java
Modified:
    wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/form/AbstractTextComponent.java
    wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/model/AbstractPropertyModel.java
    wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/util/lang/PropertyResolverTest.java

Modified: wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/form/AbstractTextComponent.java
URL: http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/form/AbstractTextComponent.java?rev=618954&r1=618953&r2=618954&view=diff
==============================================================================
--- wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/form/AbstractTextComponent.java (original)
+++ wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/form/AbstractTextComponent.java Wed Feb  6 02:50:05 2008
@@ -23,6 +23,8 @@
 import org.apache.wicket.model.IObjectClassAwareModel;
 import org.apache.wicket.util.convert.ConversionException;
 import org.apache.wicket.util.string.Strings;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 
 /**
@@ -35,6 +37,10 @@
 	// Flag for the type resolving. FLAG_RESERVED1-3 is taken by form component
 	private static final int TYPE_RESOLVED = Component.FLAG_RESERVED4;
 
+	/** Log for reporting. */
+	private static final Logger log = LoggerFactory.getLogger(AbstractTextComponent.class);
+
+
 	/**
 	 * 
 	 */
@@ -124,7 +130,13 @@
 	{
 		if (model instanceof IObjectClassAwareModel)
 		{
-			return ((IObjectClassAwareModel)model).getObjectClass();
+			Class objectClass = ((IObjectClassAwareModel)model).getObjectClass();
+			if (objectClass == null)
+			{
+				log.warn("Couldn't resolve model type of " + model + " for " + this +
+					", please set the type yourself.");
+			}
+			return objectClass;
 		}
 		else
 		{

Modified: wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/model/AbstractPropertyModel.java
URL: http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/model/AbstractPropertyModel.java?rev=618954&r1=618953&r2=618954&view=diff
==============================================================================
--- wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/model/AbstractPropertyModel.java (original)
+++ wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/model/AbstractPropertyModel.java Wed Feb  6 02:50:05 2008
@@ -41,10 +41,10 @@
  * @author Jonathan Locke
  */
 public abstract class AbstractPropertyModel
-		implements
-			IChainingModel,
-			IObjectClassAwareModel,
-			IPropertyReflectionAwareModel
+	implements
+		IChainingModel,
+		IObjectClassAwareModel,
+		IPropertyReflectionAwareModel
 {
 	/**
 	 * 
@@ -159,8 +159,8 @@
 		else
 		{
 			PropertyResolverConverter prc = null;
-			prc = new PropertyResolverConverter(Application.get().getConverterLocator(), Session
-					.get().getLocale());
+			prc = new PropertyResolverConverter(Application.get().getConverterLocator(),
+				Session.get().getLocale());
 			PropertyResolver.setValue(expression, getTarget(), object, prc);
 		}
 	}
@@ -208,7 +208,14 @@
 		final Object target = getTarget();
 		if (target != null)
 		{
-			return PropertyResolver.getPropertyClass(expression, target);
+			try
+			{
+				return PropertyResolver.getPropertyClass(expression, target);
+			}
+			catch (Exception e)
+			{
+				// ignore.
+			}
 		}
 		return null;
 	}
@@ -230,6 +237,7 @@
 				}
 				catch (Exception ignore)
 				{
+					// ignore.
 				}
 			}
 		}

Added: wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/util/lang/Country2.java
URL: http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/util/lang/Country2.java?rev=618954&view=auto
==============================================================================
--- wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/util/lang/Country2.java (added)
+++ wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/util/lang/Country2.java Wed Feb  6 02:50:05 2008
@@ -0,0 +1,46 @@
+/*
+ * 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.util.lang;
+
+/**
+ * @author jcompagner
+ */
+public class Country2 extends Country
+{
+
+	private final Country country;
+
+	/**
+	 * Construct.
+	 * 
+	 * @param name
+	 */
+	public Country2(String name, Country country)
+	{
+		super(name);
+		this.country = country;
+	}
+
+	/**
+	 * @return
+	 */
+	public Country getSubCountry()
+	{
+		return country;
+	}
+
+}

Modified: wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/util/lang/PropertyResolverTest.java
URL: http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/util/lang/PropertyResolverTest.java?rev=618954&r1=618953&r2=618954&view=diff
==============================================================================
--- wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/util/lang/PropertyResolverTest.java (original)
+++ wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/util/lang/PropertyResolverTest.java Wed Feb  6 02:50:05 2008
@@ -499,6 +499,26 @@
 	}
 
 	/**
+	 * @throws Exception
+	 */
+	public void testPropertyClassWithSubType() throws Exception
+	{
+		Person person = new Person();
+		assertEquals(String.class, PropertyResolver.getPropertyClass("country.name", person));
+		try
+		{
+			PropertyResolver.getPropertyClass("country.subCountry.name", person);
+			fail("country.subCountry shouldnt be found");
+		}
+		catch (Exception e)
+		{
+
+		}
+		person.setCountry(new Country2("test", new Country("test")));
+		PropertyResolver.getPropertyClass("country.subCountry.name", person);
+	}
+
+	/**
 	 * Used for models in testing.
 	 */
 	private static class InnerVectorPOJO extends Vector