You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by hl...@apache.org on 2008/02/26 21:43:51 UTC

svn commit: r631368 - in /tapestry/tapestry5/trunk/tapestry-core/src: main/java/org/apache/tapestry/ main/java/org/apache/tapestry/beaneditor/ main/java/org/apache/tapestry/corelib/base/ main/java/org/apache/tapestry/corelib/components/ main/java/org/a...

Author: hlship
Date: Tue Feb 26 12:43:42 2008
New Revision: 631368

URL: http://svn.apache.org/viewvc?rev=631368&view=rev
Log:
TAPESTRY-1932: Extend PropertyModel to allow access to annotations associated with the property

Modified:
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/ComponentResources.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/beaneditor/PropertyModel.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/base/AbstractTextField.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/components/PasswordField.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/components/PropertyEditor.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/components/TextArea.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/components/TextField.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/pages/PropertyEditBlocks.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/beaneditor/PropertyModelImpl.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/structure/InternalComponentResourcesImpl.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/PropertyEditContext.java
    tapestry/tapestry5/trunk/tapestry-core/src/site/apt/upgrade.apt
    tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/data/RegistrationData.java
    tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/BeanModelSourceImplTest.java

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/ComponentResources.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/ComponentResources.java?rev=631368&r1=631367&r2=631368&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/ComponentResources.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/ComponentResources.java Tue Feb 26 12:43:42 2008
@@ -21,6 +21,8 @@
 import org.apache.tapestry.runtime.Component;
 import org.apache.tapestry.runtime.PageLifecycleListener;
 
+import java.lang.annotation.Annotation;
+
 /**
  * Provides a component instance with the resources provided by the framework. In many circumstances, the resources
  * object can be considered the component itself; in others, it is the {@link #getComponent() component property}, and
@@ -83,6 +85,15 @@
      * Returns true if the named parameter is bound, false if not.
      */
     boolean isBound(String parameterName);
+
+    /**
+     * Obtains an annotation provided by a parameter.
+     *
+     * @param parameterName  name of parameter to search for the annotation
+     * @param annotationType the type of annotation
+     * @return the annotation if found or null otherwise
+     */
+    <T extends Annotation> T getParameterAnnotation(String parameterName, Class<T> annotationType);
 
     /**
      * Indentifies all parameters that are not formal parameters and writes each as a attribute/value pair into the

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/beaneditor/PropertyModel.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/beaneditor/PropertyModel.java?rev=631368&r1=631367&r2=631368&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/beaneditor/PropertyModel.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/beaneditor/PropertyModel.java Tue Feb 26 12:43:42 2008
@@ -15,11 +15,18 @@
 package org.apache.tapestry.beaneditor;
 
 import org.apache.tapestry.PropertyConduit;
+import org.apache.tapestry.ioc.AnnotationProvider;
 
 /**
- * Part of a {@link org.apache.tapestry.beaneditor.BeanModel} that defines the attributes of a single property of a bean.
+ * Part of a {@link org.apache.tapestry.beaneditor.BeanModel} that defines the attributes of a single property of a
+ * bean.
+ * <p/>
+ * <p/>
+ * A PropertyModel is also an {@link AnnotationProvider}, as long as the {@link org.apache.tapestry.PropertyConduit} is
+ * non-null.  When there is no property conduit, then {@link org.apache.tapestry.ioc.AnnotationProvider#getAnnotation(Class)}
+ * will return null.
  */
-public interface PropertyModel
+public interface PropertyModel extends AnnotationProvider
 {
     /**
      * Returns the name of the property (which may, in fact, be a property expression).
@@ -27,8 +34,8 @@
     String getPropertyName();
 
     /**
-     * Returns the id used to access other resources (this is based on the property name, but with
-     * any excess punctuation stripped out).
+     * Returns the id used to access other resources (this is based on the property name, but with any excess
+     * punctuation stripped out).
      */
     String getId();
 
@@ -43,8 +50,8 @@
     Class getPropertyType();
 
     /**
-     * Returns a logical name for the type of UI needed to view or edit the property. This is
-     * initially determined from the property type.
+     * Returns a logical name for the type of UI needed to view or edit the property. This is initially determined from
+     * the property type.
      */
     String getDataType();
 
@@ -57,27 +64,12 @@
     PropertyModel dataType(String dataType);
 
     /**
-     * Returns an object used to read or update the property. For virtual properties (properties
-     * that do not actually exist on the bean), the conduit may be null.
+     * Returns an object used to read or update the property. For virtual properties (properties that do not actually
+     * exist on the bean), the conduit may be null.
      */
     PropertyConduit getConduit();
 
     /**
-     * Returns the desired field width for the field used to edit the property.  A value of 0 or less means unspecified.
-     *
-     * @return the width of the field used to edit the property
-     */
-    int getWidth();
-
-    /**
-     * Sets the width of the field used to edit the property.
-     *
-     * @param width the desired width (0 or less indicates an unspecified width)
-     * @return the property model, for further changes
-     */
-    PropertyModel width(int width);
-
-    /**
      * Changes the label for the property to the provided value.
      *
      * @param label new label for property
@@ -91,8 +83,8 @@
     BeanModel model();
 
     /**
-     * Returns true if the property can be used for sorting. By default, this is true only if the
-     * property type implements Comparable.
+     * Returns true if the property can be used for sorting. By default, this is true only if the property type
+     * implements Comparable.
      */
     boolean isSortable();
 

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/base/AbstractTextField.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/base/AbstractTextField.java?rev=631368&r1=631367&r2=631368&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/base/AbstractTextField.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/base/AbstractTextField.java Tue Feb 26 12:43:42 2008
@@ -16,12 +16,15 @@
 
 import org.apache.tapestry.*;
 import org.apache.tapestry.annotations.*;
+import org.apache.tapestry.beaneditor.Width;
 import org.apache.tapestry.corelib.mixins.RenderDisabled;
+import org.apache.tapestry.ioc.AnnotationProvider;
 import org.apache.tapestry.ioc.annotations.Inject;
 import org.apache.tapestry.services.ComponentDefaultProvider;
 import org.apache.tapestry.services.FieldValidatorDefaultSource;
 import org.apache.tapestry.services.Request;
 
+import java.lang.annotation.Annotation;
 import java.util.Locale;
 
 /**
@@ -67,6 +70,15 @@
     private FieldValidator<Object> _validate;
 
     /**
+     * Provider of annotations used for some defaults.  Annotation are usually provided in terms of the value parameter
+     * (i.e., from the getter and/or setter bound to the value parameter).
+     *
+     * @see org.apache.tapestry.beaneditor.Width
+     */
+    @Parameter
+    private AnnotationProvider _annotationProvider;
+
+    /**
      * Defines how nulls on the server side, or sent from the client side, are treated. The selected strategy may
      * replace the nulls with some other value. The default strategy leaves nulls alone.  Another built-in strategy,
      * zero, replaces nulls with the value 0.
@@ -100,14 +112,25 @@
     private ComponentDefaultProvider _defaultProvider;
 
     /**
-     * Computes a default value for the "translate" parameter using
-     * {@link org.apache.tapestry.services.ComponentDefaultProvider#defaultTranslator(String, org.apache.tapestry.ComponentResources)}.
+     * Computes a default value for the "translate" parameter using {@link org.apache.tapestry.services.ComponentDefaultProvider#defaultTranslator(String,
+     * org.apache.tapestry.ComponentResources)}.
      */
     final Translator defaultTranslate()
     {
         return _defaultProvider.defaultTranslator("value", _resources);
     }
 
+    final AnnotationProvider defaultAnnotationProvider()
+    {
+        return new AnnotationProvider()
+        {
+            public <T extends Annotation> T getAnnotation(Class<T> annotationClass)
+            {
+                return _resources.getParameterAnnotation("value", annotationClass);
+            }
+        };
+    }
+
     /**
      * Computes a default value for the "validate" parameter using {@link FieldValidatorDefaultSource}.
      */
@@ -131,7 +154,7 @@
         return createDefaultParameterBinding("value");
     }
 
-    @SuppressWarnings({"unchecked"})
+    @SuppressWarnings({ "unchecked" })
     @BeginRender
     final void begin(MarkupWriter writer)
     {
@@ -160,8 +183,8 @@
 
     /**
      * Invoked from {@link #begin(MarkupWriter)} to write out the element and attributes (typically, &lt;input&gt;). The
-     * {@linkplain AbstractField#getControlName() controlName} and {@linkplain AbstractField#getClientId() clientId} properties
-     * will already have been set or updated.
+     * {@linkplain AbstractField#getControlName() controlName} and {@linkplain AbstractField#getClientId() clientId}
+     * properties will already have been set or updated.
      * <p/>
      * Generally, the subclass will invoke {@link MarkupWriter#element(String, Object[])}, and will be responsible for
      * including an {@link AfterRender} phase method to invoke {@link MarkupWriter#end()}.
@@ -171,7 +194,7 @@
      */
     protected abstract void writeFieldTag(MarkupWriter writer, String value);
 
-    @SuppressWarnings({"unchecked"})
+    @SuppressWarnings({ "unchecked" })
     @Override
     protected final void processSubmission(String elementName)
     {
@@ -197,5 +220,20 @@
     public boolean isRequired()
     {
         return _validate.isRequired();
+    }
+
+    /**
+     * Looks for a {@link org.apache.tapestry.beaneditor.Width} annotation and, if present, returns its value as a
+     * string.
+     *
+     * @return the indicated width, or null if the annotation is not present
+     */
+    protected final String getWidth()
+    {
+        Width width = _annotationProvider.getAnnotation(Width.class);
+
+        if (width == null) return null;
+
+        return Integer.toString(width.value());
     }
 }

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/components/PasswordField.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/components/PasswordField.java?rev=631368&r1=631367&r2=631368&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/components/PasswordField.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/components/PasswordField.java Tue Feb 26 12:43:42 2008
@@ -18,8 +18,11 @@
 import org.apache.tapestry.corelib.base.AbstractTextField;
 
 /**
- * A version of {@link TextField}, but rendered out as an &lt;input type="password"&gt; element.
- * Further, the output value for a PasswordField is always blank.
+ * A version of {@link TextField}, but rendered out as an &lt;input type="password"&gt; element. Further, the output
+ * value for a PasswordField is always blank.
+ * <p/>
+ * Includes the <code>size</code> attribute, if a {@link org.apache.tapestry.beaneditor.Width} annotation is present on
+ * the property bound to the value parameter.
  */
 public class PasswordField extends AbstractTextField
 {
@@ -35,7 +38,9 @@
 
                        "id", getClientId(),
 
-                       "value", "");
+                       "value", "",
+
+                       "size", getWidth());
     }
 
     final void afterRender(MarkupWriter writer)

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/components/PropertyEditor.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/components/PropertyEditor.java?rev=631368&r1=631367&r2=631368&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/components/PropertyEditor.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/components/PropertyEditor.java Tue Feb 26 12:43:42 2008
@@ -24,6 +24,7 @@
 import org.apache.tapestry.ioc.internal.util.TapestryException;
 import org.apache.tapestry.services.*;
 
+import java.lang.annotation.Annotation;
 import java.util.Locale;
 
 /**
@@ -71,10 +72,9 @@
     private Object _object;
 
     /**
-     * Where to search for local overrides of property editing blocks as block parameters.
-     * This is normally the containing component of the PropertyEditor, but
-     * when the component is used within a BeanEditor, it will be the BeanEditForm's block parameters that will be
-     * searched.
+     * Where to search for local overrides of property editing blocks as block parameters. This is normally the
+     * containing component of the PropertyEditor, but when the component is used within a BeanEditor, it will be the
+     * BeanEditForm's block parameters that will be searched.
      */
     @Parameter(value = "componentResources.containerResources")
     private ComponentResources _overrides;
@@ -118,7 +118,8 @@
     private TranslatorSource _translatorSource;
 
     /**
-     * Creates a {@link PropertyEditContext} and pushes it onto the {@link Environment} stack.
+     * Creates a {@link org.apache.tapestry.services.PropertyEditContext} and pushes it onto the {@link
+     * org.apache.tapestry.services.Environment} stack.
      */
     void setupEnvironment(final String propertyName)
     {
@@ -169,9 +170,9 @@
                 _propertyModel.getConduit().set(_object, value);
             }
 
-            public int getWidth()
+            public <T extends Annotation> T getAnnotation(Class<T> annotationClass)
             {
-                return _propertyModel.getWidth();
+                return _propertyModel.getAnnotation(annotationClass);
             }
         };
 

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/components/TextArea.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/components/TextArea.java?rev=631368&r1=631367&r2=631368&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/components/TextArea.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/components/TextArea.java Tue Feb 26 12:43:42 2008
@@ -18,10 +18,13 @@
 import org.apache.tapestry.corelib.base.AbstractTextField;
 
 /**
- * TextArea component corresponds to a &lt;textarea&gt; element. The value parameter is almost
- * always bound to a string, but this is not an absolute requirement.
+ * TextArea component corresponds to a &lt;textarea&gt; element. The value parameter is almost always bound to a string,
+ * but this is not an absolute requirement.
+ * <p/>
+ * Includes the <code>cols</code> attribute, if a {@link org.apache.tapestry.beaneditor.Width} annotation is present on
+ * the property bound to the value parameter.
  *
- * @see TextOutput
+ * @see org.apache.tapestry.corelib.components.TextOutput
  */
 public final class TextArea extends AbstractTextField
 {
@@ -34,7 +37,9 @@
 
                        "name", getControlName(),
 
-                       "id", getClientId());
+                       "id", getClientId(),
+
+                       "cols", getWidth());
 
         // Save until needed in after()
 

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/components/TextField.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/components/TextField.java?rev=631368&r1=631367&r2=631368&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/components/TextField.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/components/TextField.java Tue Feb 26 12:43:42 2008
@@ -18,9 +18,12 @@
 import org.apache.tapestry.corelib.base.AbstractTextField;
 
 /**
- * TextField component corresponds to &lt;input type="text"&gt; element. The value parameter will be
- * editted. TextField is generally used with string values, but other values are acceptible, as long
- * as they can be freely converted back and forth to strings.
+ * TextField component corresponds to &lt;input type="text"&gt; element. The value parameter will be editted. TextField
+ * is generally used with string values, but other values are acceptible, as long as they can be freely converted back
+ * and forth to strings.
+ * <p/>
+ * Includes the <code>size</code> attribute, if a {@link org.apache.tapestry.beaneditor.Width} annotation is present on
+ * the property bound to the value parameter.
  */
 public final class TextField extends AbstractTextField
 {
@@ -35,7 +38,9 @@
 
                        "id", getClientId(),
 
-                       "value", value);
+                       "value", value,
+
+                       "size", getWidth());
     }
 
     final void afterRender(MarkupWriter writer)

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/pages/PropertyEditBlocks.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/pages/PropertyEditBlocks.java?rev=631368&r1=631367&r2=631368&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/pages/PropertyEditBlocks.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/pages/PropertyEditBlocks.java Tue Feb 26 12:43:42 2008
@@ -27,8 +27,8 @@
 import org.apache.tapestry.util.EnumValueEncoder;
 
 /**
- * A page that exists to contain blocks used to edit different types of properties. The blocks on
- * this page are contributed into the {@link BeanBlockSource} service configuration.
+ * A page that exists to contain blocks used to edit different types of properties. The blocks on this page are
+ * contributed into the {@link BeanBlockSource} service configuration.
  *
  * @see BeanBlockContribution
  * @see BeanEditForm
@@ -39,29 +39,29 @@
     private PropertyEditContext _context;
 
     @Component(
-            parameters = {"value=context.propertyValue", "label=prop:context.label", "translate=prop:context.translator", "validate=prop:textFieldValidator", "clientId=prop:context.propertyId", "size=prop:widthOrNull"})
+            parameters = { "value=context.propertyValue", "label=prop:context.label", "translate=prop:context.translator", "validate=prop:textFieldValidator", "clientId=prop:context.propertyId", "annotationProvider=context" })
     private TextField _textField;
 
     @Component(
-            parameters = {"value=context.propertyValue", "label=prop:context.label", "encoder=valueEncoderForProperty", "model=selectModelForProperty", "validate=prop:selectValidator", "clientId=prop:context.propertyId"})
+            parameters = { "value=context.propertyValue", "label=prop:context.label", "encoder=valueEncoderForProperty", "model=selectModelForProperty", "validate=prop:selectValidator", "clientId=prop:context.propertyId" })
     private Select _select;
 
     @SuppressWarnings("unused")
     @Component(
-            parameters = {"value=context.propertyValue", "label=prop:context.label", "clientId=prop:context.propertyId"})
+            parameters = { "value=context.propertyValue", "label=prop:context.label", "clientId=prop:context.propertyId" })
     private Checkbox _checkboxField;
 
     @SuppressWarnings("unused")
     @Component(
-            parameters = {"value=context.propertyValue", "label=prop:context.label", "clientId=prop:context.propertyid", "validate=prop:dateFieldValidator"})
+            parameters = { "value=context.propertyValue", "label=prop:context.label", "clientId=prop:context.propertyid", "validate=prop:dateFieldValidator" })
     private DateField _dateField;
 
     @Component(
-            parameters = {"value=context.propertyValue", "label=prop:context.label", "translate=prop:context.translator", "validate=prop:passwordFieldValidator", "clientId=prop:context.propertyId", "size=prop:widthOrNull"})
+            parameters = { "value=context.propertyValue", "label=prop:context.label", "translate=prop:context.translator", "validate=prop:passwordFieldValidator", "clientId=prop:context.propertyId", "annotationProvider=context" })
     private PasswordField _passwordField;
 
     @Component(
-            parameters = {"value=context.propertyValue", "label=prop:context.label", "translate=prop:context.translator", "validate=prop:textAreaValidator", "clientId=prop:context.propertyId", "cols=prop:widthOrNull"})
+            parameters = { "value=context.propertyValue", "label=prop:context.label", "translate=prop:context.translator", "validate=prop:textAreaValidator", "clientId=prop:context.propertyId", "annotationProvider=context" })
     private TextArea _textArea;
 
 
@@ -114,12 +114,5 @@
     public SelectModel getSelectModelForProperty()
     {
         return new EnumSelectModel(_context.getPropertyType(), _context.getContainerMessages());
-    }
-
-    public Integer getWidthOrNull()
-    {
-        int width = _context.getWidth();
-
-        return width < 1 ? null : width;
     }
 }

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/beaneditor/PropertyModelImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/beaneditor/PropertyModelImpl.java?rev=631368&r1=631367&r2=631368&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/beaneditor/PropertyModelImpl.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/beaneditor/PropertyModelImpl.java Tue Feb 26 12:43:42 2008
@@ -1,4 +1,4 @@
-// Copyright 2007 The Apache Software Foundation
+// Copyright 2007, 2008 The Apache Software Foundation
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -17,12 +17,13 @@
 import org.apache.tapestry.PropertyConduit;
 import org.apache.tapestry.beaneditor.BeanModel;
 import org.apache.tapestry.beaneditor.PropertyModel;
-import org.apache.tapestry.beaneditor.Width;
 import org.apache.tapestry.internal.TapestryInternalUtils;
 import org.apache.tapestry.ioc.Messages;
 import static org.apache.tapestry.ioc.internal.util.Defense.notBlank;
 import org.apache.tapestry.ioc.services.ClassFabUtils;
 
+import java.lang.annotation.Annotation;
+
 public class PropertyModelImpl implements PropertyModel
 {
     private final BeanModel _model;
@@ -39,8 +40,6 @@
 
     private boolean _sortable;
 
-    private int _width;
-
     public PropertyModelImpl(BeanModel model, String name, PropertyConduit conduit, Messages messages)
     {
         _model = model;
@@ -57,14 +56,6 @@
         Class wrapperType = ClassFabUtils.getWrapperType(getPropertyType());
 
         _sortable = Comparable.class.isAssignableFrom(wrapperType);
-
-        // Extract a default width from the @Width annotation, if present
-        if (conduit != null)
-        {
-            Width width = conduit.getAnnotation(Width.class);
-
-            if (width != null) _width = width.value();
-        }
     }
 
     public String getId()
@@ -130,15 +121,8 @@
         return this;
     }
 
-    public int getWidth()
+    public <T extends Annotation> T getAnnotation(Class<T> annotationClass)
     {
-        return _width;
-    }
-
-    public PropertyModel width(int width)
-    {
-        _width = width;
-
-        return this;
+        return _conduit == null ? null : _conduit.getAnnotation(annotationClass);
     }
 }

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/structure/InternalComponentResourcesImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/structure/InternalComponentResourcesImpl.java?rev=631368&r1=631367&r2=631368&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/structure/InternalComponentResourcesImpl.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/structure/InternalComponentResourcesImpl.java Tue Feb 26 12:43:42 2008
@@ -32,6 +32,7 @@
 import org.apache.tapestry.runtime.RenderQueue;
 import org.slf4j.Logger;
 
+import java.lang.annotation.Annotation;
 import java.util.Locale;
 import java.util.Map;
 
@@ -147,6 +148,15 @@
     public boolean isBound(String parameterName)
     {
         return getBinding(parameterName) != null;
+    }
+
+    public <T extends Annotation> T getParameterAnnotation(String parameterName, Class<T> annotationType)
+    {
+        Binding b = getBinding(parameterName);
+
+        if (b == null) return null;
+
+        return b.getAnnotation(annotationType);
     }
 
     public boolean isRendering()

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/PropertyEditContext.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/PropertyEditContext.java?rev=631368&r1=631367&r2=631368&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/PropertyEditContext.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/PropertyEditContext.java Tue Feb 26 12:43:42 2008
@@ -1,4 +1,4 @@
-// Copyright 2007 The Apache Software Foundation
+// Copyright 2007, 2008 The Apache Software Foundation
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -17,37 +17,33 @@
 import org.apache.tapestry.Field;
 import org.apache.tapestry.FieldValidator;
 import org.apache.tapestry.Translator;
-import org.apache.tapestry.annotations.Environmental;
-import org.apache.tapestry.beaneditor.Validate;
-import org.apache.tapestry.corelib.components.BeanEditForm;
-import org.apache.tapestry.corelib.components.Label;
+import org.apache.tapestry.ioc.AnnotationProvider;
 import org.apache.tapestry.ioc.Messages;
 
 /**
- * Defines a context for editing a property of a bean via {@link org.apache.tapestry.corelib.components.BeanEditor}. This value is made
- * available to blocks via the {@link Environmental} annotation.
+ * Defines a context for editing a property of a bean via {@link org.apache.tapestry.corelib.components.BeanEditor}.
+ * This value is made available to blocks via the {@link org.apache.tapestry.annotations.Environmental} annotation.
  *
- * @see BeanBlockSource
+ * @see org.apache.tapestry.services.BeanBlockSource
  */
-public interface PropertyEditContext
+public interface PropertyEditContext extends AnnotationProvider
 {
     /**
-     * Returns the current value of the property being edited (the context encapsulates the object
-     * containing the property).
+     * Returns the current value of the property being edited (the context encapsulates the object containing the
+     * property).
      */
     Object getPropertyValue();
 
     /**
-     * Updates the value of the property being edited (the context encapsulates the object
-     * containing the property).
+     * Updates the value of the property being edited (the context encapsulates the object containing the property).
      *
      * @param value new value for the property
      */
     void setPropertyValue(Object value);
 
     /**
-     * Returns the user-presentable label, for use with the {@link Label} component, or to be
-     * integrated into any validation error messages.
+     * Returns the user-presentable label, for use with the {@link org.apache.tapestry.corelib.components.Label}
+     * component, or to be integrated into any validation error messages.
      */
     String getLabel();
 
@@ -61,14 +57,14 @@
     /**
      * Returns the FieldValidator for the field.
      *
-     * @see Validate
-     * @see FieldValidatorDefaultSource
+     * @see org.apache.tapestry.beaneditor.Validate
+     * @see org.apache.tapestry.services.FieldValidatorDefaultSource
      */
     FieldValidator getValidator(Field field);
 
     /**
-     * Returns a string that identifies the property, usually the property name. This is used as the
-     * basis for the client-side client id.
+     * Returns a string that identifies the property, usually the property name. This is used as the basis for the
+     * client-side client id.
      */
     String getPropertyId();
 
@@ -78,13 +74,8 @@
     Class getPropertyType();
 
     /**
-     * Returns the message catalog for the container of the {@link BeanEditForm}, which is the
-     * correct place to look for strings used for labels, etc.
+     * Returns the message catalog for the container of the {@link org.apache.tapestry.corelib.components.BeanEditForm},
+     * which is the correct place to look for strings used for labels, etc.
      */
     Messages getContainerMessages();
-
-    /**
-     * Returns the desired width of the input field used to edit the property. A value less than 1 is an unspecified width.
-     */
-    int getWidth();
 }

Modified: tapestry/tapestry5/trunk/tapestry-core/src/site/apt/upgrade.apt
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/site/apt/upgrade.apt?rev=631368&r1=631367&r2=631368&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/site/apt/upgrade.apt (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/site/apt/upgrade.apt Tue Feb 26 12:43:42 2008
@@ -43,4 +43,10 @@
   The {{{../apidocs/org/apache/tapestry/grid/GridModel.html}GridModel}} and
   the <<<prepare()>>> method of 
   {{{../apidocs/org/apache/tapestry/grid/GridDataSource.html}GridDataSource}} have changed to accomidate
-  the ability to sort using multiple columns.
\ No newline at end of file
+  the ability to sort using multiple columns.
+
+* PropertyModel
+
+  The <<<getWidth()>>> method was removed from the
+  {{{../apidocs/org/apache/tapestry/beaneditor/PropertyModel.java}PropertyModel}} interface; the logic
+  for deducing the desired field size from the @Width annotation has been moved into AbstractTextField.
\ No newline at end of file

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/data/RegistrationData.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/data/RegistrationData.java?rev=631368&r1=631367&r2=631368&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/data/RegistrationData.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/data/RegistrationData.java Tue Feb 26 12:43:42 2008
@@ -1,4 +1,4 @@
-// Copyright 2007 The Apache Software Foundation
+// Copyright 2007, 2008 The Apache Software Foundation
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -102,6 +102,7 @@
     }
 
     @DataType("longtext")
+    @Width(50)
     public String getNotes()
     {
         return _notes;

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/BeanModelSourceImplTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/BeanModelSourceImplTest.java?rev=631368&r1=631367&r2=631368&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/BeanModelSourceImplTest.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/BeanModelSourceImplTest.java Tue Feb 26 12:43:42 2008
@@ -80,14 +80,12 @@
         assertEquals(age.getLabel(), "Age");
         assertSame(age.getPropertyType(), int.class);
         assertEquals(age.getDataType(), "text");
-        assertEquals(age.getWidth(), 2);
 
         PropertyModel firstName = model.get("firstName");
 
         assertEquals(firstName.getLabel(), "First Name");
         assertEquals(firstName.getPropertyType(), String.class);
         assertEquals(firstName.getDataType(), "text");
-        assertEquals(firstName.getWidth(), 0);
 
         assertEquals(model.get("lastName").getLabel(), "Last Name");