Author: hlship
Date: Thu Jan 17 12:10:52 2008
New Revision: 612962

URL: http://svn.apache.org/viewvc?rev=612962&view=rev
Log:
TAPESTRY-1739: Add byte, short and float Translators

Added:
    
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/translator/IntegerTranslator.java
      - copied, changed from r594319, 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/translator/IntegerTranslator.java
    
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/translator/LongTranslator.java
      - copied, changed from r594319, 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/translator/LongTranslator.java
Modified:
    
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/PropertyEditor.java

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=612962&r1=612961&r2=612962&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
 Thu Jan 17 12:10:52 2008
@@ -26,44 +26,42 @@
 import java.util.Locale;
 
 /**
- * Abstract class for a variety of components that render some variation of a 
text field. Most of
- * the hooks for user input validation are in this class.
+ * Abstract class for a variety of components that render some variation of a 
text field. Most of the hooks for user
+ * input validation are in this class.
  * <p/>
- * In particular, all subclasses support the "toclient" and "parseclient" 
events.  These two events
- * allow the normal [EMAIL PROTECTED] Translator} (specified by the translate 
parameter, but often automatically
- * derived by Tapestry) to be augmented.
+ * In particular, all subclasses support the "toclient" and "parseclient" 
events.  These two events allow the normal
+ * [EMAIL PROTECTED] Translator} (specified by the translate parameter, but 
often automatically derived by Tapestry) to be
+ * augmented.
  * <p/>
- * If the component container (i.e., the page) provides an event handler 
method for the "toclient" event,
- * and that handler returns a non-null string, that will be the string value 
sent to the client. The context
- * passed to the event handler method is the current value of the value 
parameter.
+ * If the component container (i.e., the page) provides an event handler 
method for the "toclient" event, and that
+ * handler returns a non-null string, that will be the string value sent to 
the client. The context passed to the event
+ * handler method is the current value of the value parameter.
  * <p/>
- * Likewise, on a form submit, the "parseclient" event handler method will be 
passed the string provided
- * by the client, and may provide a non-null value as the parsed value.  
Returning null allows the normal
- * translator to operate.  The event handler may also throw [EMAIL PROTECTED] 
org.apache.tapestry.ValidationException}.
+ * Likewise, on a form submit, the "parseclient" event handler method will be 
passed the string provided by the client,
+ * and may provide a non-null value as the parsed value.  Returning null 
allows the normal translator to operate.  The
+ * event handler may also throw [EMAIL PROTECTED] 
org.apache.tapestry.ValidationException}.
  */
 public abstract class AbstractTextField extends AbstractField
 {
     /**
-     * The value to be read and updated. This is not necessarily a string, a 
translator may be
-     * provided to convert between client side and server side 
representations. If not bound, a
-     * default binding is made to a property of the container matching the 
component's id. If no
-     * such property exists, then you will see a runtime exception due to the 
unbound value
-     * parameter.
+     * The value to be read and updated. This is not necessarily a string, a 
translator may be provided to convert
+     * between client side and server side representations. If not bound, a 
default binding is made to a property of the
+     * container matching the component's id. If no such property exists, then 
you will see a runtime exception due to
+     * the unbound value parameter.
      */
     @Parameter(required = true, principal = true)
     private Object _value;
 
     /**
-     * The object which will perform translation between server-side and 
client-side
-     * representations. If not specified, a value will usually be generated 
based on the type of the
-     * value parameter.
+     * The object which will perform translation between server-side and 
client-side representations. If not specified,
+     * a value will usually be generated based on the type of the value 
parameter.
      */
     @Parameter(required = true)
     private Translator<Object> _translate;
 
     /**
-     * The object that will perform input validation (which occurs after 
translation). The translate
-     * binding prefix is generally used to provide this object in a 
declarative fashion.
+     * The object that will perform input validation (which occurs after 
translation). The translate binding prefix is
+     * generally used to provide this object in a declarative fashion.
      */
     @Parameter(defaultPrefix = "validate")
     @SuppressWarnings("unchecked")
@@ -106,12 +104,11 @@
 
         if (type == null) return null;
 
-        return _translatorDefaultSource.find(type);
+        return _translatorDefaultSource.get(type);
     }
 
     /**
-     * Computes a default value for the "validate" parameter using
-     * [EMAIL PROTECTED] FieldValidatorDefaultSource}.
+     * Computes a default value for the "validate" parameter using [EMAIL 
PROTECTED] FieldValidatorDefaultSource}.
      */
     final FieldValidator defaultValidate()
     {
@@ -125,8 +122,8 @@
     }
 
     /**
-     * The default value is a property of the container whose name matches the 
component's id. May
-     * return null if the container does not have a matching property.
+     * The default value is a property of the container whose name matches the 
component's id. May return null if the
+     * container does not have a matching property.
      */
     final Binding defaultValue()
     {
@@ -151,18 +148,15 @@
     }
 
     /**
-     * Invoked from [EMAIL PROTECTED] #begin(MarkupWriter)} to write out the 
element and attributes (typically,
-     * &lt;input&gt;). The [EMAIL PROTECTED] AbstractField#getElementName() 
elementName} and
-     * [EMAIL PROTECTED] AbstractField#getClientId() clientId} properties will 
already have been set or
-     * updated.
+     * Invoked from [EMAIL PROTECTED] #begin(MarkupWriter)} to write out the 
element and attributes (typically, &lt;input&gt;). The
+     * [EMAIL PROTECTED] AbstractField#getElementName() elementName} and 
[EMAIL PROTECTED] AbstractField#getClientId() clientId} properties
+     * will already have been set or updated.
      * <p/>
-     * Generally, the subclass will invoke [EMAIL PROTECTED] 
MarkupWriter#element(String, Object[])}, and will
-     * be responsible for including an [EMAIL PROTECTED] AfterRender} phase 
method to invoke
-     * [EMAIL PROTECTED] MarkupWriter#end()}.
+     * Generally, the subclass will invoke [EMAIL PROTECTED] 
MarkupWriter#element(String, Object[])}, and will be responsible for
+     * including an [EMAIL PROTECTED] AfterRender} phase method to invoke 
[EMAIL PROTECTED] MarkupWriter#end()}.
      *
      * @param writer markup write to send output to
-     * @param value  the value (either obtained and translated from the value 
parameter, or obtained
-     *               from the tracker)
+     * @param value  the value (either obtained and translated from the value 
parameter, or obtained from the tracker)
      */
     protected abstract void writeFieldTag(MarkupWriter writer, String value);
 

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=612962&r1=612961&r2=612962&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
 Thu Jan 17 12:10:52 2008
@@ -27,9 +27,8 @@
 import java.util.Locale;
 
 /**
- * Used to edit a single property of a bean. This is used primarily by [EMAIL 
PROTECTED] BeanEditForm}. Unlike
- * BeanEditForm, the object to be edited must already exist and the [EMAIL 
PROTECTED] BeanModel model}
- * must be passed in explicitly.
+ * Used to edit a single property of a bean. This is used primarily by [EMAIL 
PROTECTED] BeanEditForm}. Unlike BeanEditForm, the
+ * object to be edited must already exist and the [EMAIL PROTECTED] BeanModel 
model} must be passed in explicitly.
  */
 public class PropertyEditor
 {
@@ -64,19 +63,18 @@
     }
 
     /**
-     * The object to be edited by the BeanEditor. This will be read when the 
component renders and
-     * updated when the form for the component is submitted. Typically, the 
container will listen
-     * for a "prepare" event, in order to ensure that a non-null value is 
ready to be read or
-     * updated.
+     * The object to be edited by the BeanEditor. This will be read when the 
component renders and updated when the form
+     * for the component is submitted. Typically, the container will listen 
for a "prepare" event, in order to ensure
+     * that a non-null value is ready to be read or updated.
      */
     @Parameter(required = true)
     private Object _object;
 
     /**
-     * Where to search for local overrides of property editing blocks as block 
parameters. Further,
-     * the container of the overrides is used as the source for overridden 
validation messages. This
-     * is normally the component itself, but when the component is used within 
a BeanEditForm, it
-     * will be the BeanEditForm's block parameter that will be searched.
+     * Where to search for local overrides of property editing blocks as block 
parameters. Further, the container of the
+     * overrides is used as the source for overridden validation messages. 
This is normally the component itself, but
+     * when the component is used within a BeanEditForm, it will be the 
BeanEditForm's block parameter that will be
+     * searched.
      */
     @Parameter(value = "componentResources")
     private ComponentResources _overrides;
@@ -155,7 +153,7 @@
 
             public Translator getTranslator()
             {
-                return 
_translatorDefaultSource.find(_propertyModel.getPropertyType());
+                return 
_translatorDefaultSource.get(_propertyModel.getPropertyType());
             }
 
             public FieldValidator getValidator(Field field)
@@ -181,8 +179,8 @@
     }
 
     /**
-     * Called at the end of the form render (or at the end of the form 
submission) to clean up the
-     * [EMAIL PROTECTED] Environment} stack.
+     * Called at the end of the form render (or at the end of the form 
submission) to clean up the [EMAIL PROTECTED] Environment}
+     * stack.
      */
     void cleanupEnvironment()
     {
@@ -212,8 +210,8 @@
     }
 
     /**
-     * Returns a Block for rendering the property. The Block will be able to 
access the
-     * [EMAIL PROTECTED] PropertyEditContext} via the [EMAIL PROTECTED] 
Environmental} annotation.
+     * Returns a Block for rendering the property. The Block will be able to 
access the [EMAIL PROTECTED] PropertyEditContext} via
+     * the [EMAIL PROTECTED] Environmental} annotation.
      */
     Block beginRender()
     {
@@ -240,8 +238,7 @@
     }
 
     /**
-     * Returns false, to prevent the rendering of the body of the component. 
PropertyEditor should
-     * not have a body.
+     * Returns false, to prevent the rendering of the body of the component. 
PropertyEditor should not have a body.
      */
     boolean beforeRenderBody()
     {

Copied: 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/translator/IntegerTranslator.java
 (from r594319, 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/translator/IntegerTranslator.java)
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/translator/IntegerTranslator.java?p2=tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/translator/IntegerTranslator.java&p1=tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/translator/IntegerTranslator.java&r1=594319&r2=612962&rev=612962&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/translator/IntegerTranslator.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/translator/IntegerTranslator.java
 Thu Jan 17 12:10:52 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.
@@ -12,12 +12,11 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-package org.apache.tapestry.translator;
+package org.apache.tapestry.internal.translator;
 
 import org.apache.tapestry.Translator;
 import org.apache.tapestry.ValidationException;
 import org.apache.tapestry.ioc.Messages;
-import org.apache.tapestry.ioc.internal.util.InternalUtils;
 
 /**
  * A translator for type integer.
@@ -31,8 +30,6 @@
      */
     public Integer parseClient(String clientValue, Messages messages) throws 
ValidationException
     {
-        if (InternalUtils.isBlank(clientValue))
-            return null;
 
         try
         {
@@ -49,7 +46,7 @@
      */
     public String toClient(Integer value)
     {
-        return value == null ? "" : value.toString();
+        return value.toString();
     }
 
 }

Copied: 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/translator/LongTranslator.java
 (from r594319, 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/translator/LongTranslator.java)
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/translator/LongTranslator.java?p2=tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/translator/LongTranslator.java&p1=tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/translator/LongTranslator.java&r1=594319&r2=612962&rev=612962&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/translator/LongTranslator.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/translator/LongTranslator.java
 Thu Jan 17 12:10:52 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.
@@ -12,12 +12,11 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-package org.apache.tapestry.translator;
+package org.apache.tapestry.internal.translator;
 
 import org.apache.tapestry.Translator;
 import org.apache.tapestry.ValidationException;
 import org.apache.tapestry.ioc.Messages;
-import org.apache.tapestry.ioc.internal.util.InternalUtils;
 
 /**
  * A translator for type long.
@@ -31,8 +30,6 @@
      */
     public Long parseClient(String clientValue, Messages messages) throws 
ValidationException
     {
-        if (InternalUtils.isBlank(clientValue))
-            return null;
 
         try
         {
@@ -49,6 +46,6 @@
      */
     public String toClient(Long value)
     {
-        return value == null ? "" : value.toString();
+        return value.toString();
     }
 }


Reply via email to