You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by an...@apache.org on 2006/08/01 02:59:15 UTC

svn commit: r427390 - in /tapestry/tapestry4/trunk/tapestry-annotations/src: java/org/apache/tapestry/annotations/ test/org/apache/tapestry/annotations/

Author: andyhot
Date: Mon Jul 31 17:59:14 2006
New Revision: 427390

URL: http://svn.apache.org/viewvc?rev=427390&view=rev
Log:
TAPESTRY-994: If component type is left unspecified, use the return type's class name.

Modified:
    tapestry/tapestry4/trunk/tapestry-annotations/src/java/org/apache/tapestry/annotations/Component.java
    tapestry/tapestry4/trunk/tapestry-annotations/src/java/org/apache/tapestry/annotations/ComponentAnnotationWorker.java
    tapestry/tapestry4/trunk/tapestry-annotations/src/test/org/apache/tapestry/annotations/AnnotatedPage.java
    tapestry/tapestry4/trunk/tapestry-annotations/src/test/org/apache/tapestry/annotations/TestComponentAnnotationWorker.java

Modified: tapestry/tapestry4/trunk/tapestry-annotations/src/java/org/apache/tapestry/annotations/Component.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-annotations/src/java/org/apache/tapestry/annotations/Component.java?rev=427390&r1=427389&r2=427390&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-annotations/src/java/org/apache/tapestry/annotations/Component.java (original)
+++ tapestry/tapestry4/trunk/tapestry-annotations/src/java/org/apache/tapestry/annotations/Component.java Mon Jul 31 17:59:14 2006
@@ -41,10 +41,10 @@
     String id() default "";
 
     /**
-     * The component type.
+     * The component type. Defaults to the return type class name if left unspecified.
      */
 
-    String type();
+    String type() default "";
 
     /**
      * If true, then the component inherits informal parameters from its container.

Modified: tapestry/tapestry4/trunk/tapestry-annotations/src/java/org/apache/tapestry/annotations/ComponentAnnotationWorker.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-annotations/src/java/org/apache/tapestry/annotations/ComponentAnnotationWorker.java?rev=427390&r1=427389&r2=427390&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-annotations/src/java/org/apache/tapestry/annotations/ComponentAnnotationWorker.java (original)
+++ tapestry/tapestry4/trunk/tapestry-annotations/src/java/org/apache/tapestry/annotations/ComponentAnnotationWorker.java Mon Jul 31 17:59:14 2006
@@ -44,11 +44,17 @@
         Component component = method.getAnnotation(Component.class);
 
         String propertyName = AnnotationUtils.getPropertyName(method);
+        String type = component.type();
+        if (type.equals(""))
+        {
+            Class retTypeClazz = method.getReturnType();
+            type = retTypeClazz.getSimpleName();
+        }
 
         IContainedComponent cc = new ContainedComponent();
 
         cc.setInheritInformalParameters(component.inheritInformalParameters());
-        cc.setType(component.type());
+        cc.setType(type);
         cc.setPropertyName(propertyName);
         cc.setLocation(location);
 

Modified: tapestry/tapestry4/trunk/tapestry-annotations/src/test/org/apache/tapestry/annotations/AnnotatedPage.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-annotations/src/test/org/apache/tapestry/annotations/AnnotatedPage.java?rev=427390&r1=427389&r2=427390&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-annotations/src/test/org/apache/tapestry/annotations/AnnotatedPage.java (original)
+++ tapestry/tapestry4/trunk/tapestry-annotations/src/test/org/apache/tapestry/annotations/AnnotatedPage.java Mon Jul 31 17:59:14 2006
@@ -100,6 +100,9 @@
 
     @InjectPage("SomePageName")
     public abstract IPage getMyPage();
+    
+    @Component
+    public abstract TextField getUsernameField();
 
     @Component(type = "TextField")
     public abstract TextField getTextField();

Modified: tapestry/tapestry4/trunk/tapestry-annotations/src/test/org/apache/tapestry/annotations/TestComponentAnnotationWorker.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-annotations/src/test/org/apache/tapestry/annotations/TestComponentAnnotationWorker.java?rev=427390&r1=427389&r2=427390&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-annotations/src/test/org/apache/tapestry/annotations/TestComponentAnnotationWorker.java (original)
+++ tapestry/tapestry4/trunk/tapestry-annotations/src/test/org/apache/tapestry/annotations/TestComponentAnnotationWorker.java Mon Jul 31 17:59:14 2006
@@ -65,6 +65,13 @@
         assertEquals(true, cc.getBindingNames().isEmpty());
         assertEquals("textField", cc.getPropertyName());
     }
+    
+    public void testWithoutType()
+    {
+        IContainedComponent cc = run("usernameField", "getUsernameField", null);
+        
+        assertEquals("TextField", cc.getType());
+    }
 
     public void testExplicitId()
     {