You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Imran Amajd <mr...@gmail.com> on 2007/10/12 09:22:17 UTC

how to translate input into double/float value

Hello,

Please guide me how i can translate input value into double or float. Thanks

-Imran Amjad
-- 
View this message in context: http://www.nabble.com/how-to-translate-input-into-double-float-value-tf4611891.html#a13170402
Sent from the Tapestry - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: how to translate input into double/float value

Posted by Imran Amajd <mr...@gmail.com>.
How can we add DoubleTranslator.java into Existing application?? 

Thanks.



Nick Westgate wrote:
> 
> You provide a translator. The framework provides one for Double etc:
> http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/translator/
> 
> You can add more in your AppModule.java, like this ...
> (I know this seems like overkill, but will likely be improved later.)
> 
>      // add a Float translator
>      public static void contributeTranslatorDefaultSource(
>          MappedConfiguration<Class<?>, Translator<?>> configuration)
>      {
>          configuration.add(Float.class, new Translator<Float>()
>          {
>              /**
>               * Parses blank values to null, otherwise parses the client
> value to a float
>               *
>               * @throws ValidationException if the clientValue can not be
> parsed
>               */
>              public Float parseClient(String clientValue, Messages
> messages)
>                  throws ValidationException
>              {
>                  if (InternalUtils.isBlank(clientValue))
>                      return null;
> 
>                  try
>                  {
>                      Float result = new Float(clientValue.trim());
>                      if (result.isInfinite())
>                      {
>                          throw new
> ValidationException(messages.format("number-range-exception",
>                              clientValue));
>                      }
>                      return result;
>                  }
>                  catch (NumberFormatException ex)
>                  {
>                      throw new
> ValidationException(messages.format("number-format-exception",
>                          clientValue));
>                  }
>              }
> 
>              /**
>               * Converts null to the blank string, non-null to a string
> representation.
>               */
>              public String toClient(Float value)
>              {
>                  return value == null ? "" : value.toString();
>              }
>          });
>      }
> 
> Cheers,
> Nick.
> 
> 
> Imran Amajd wrote:
>> Hello,
>> 
>> Please guide me how i can translate input value into double or float.
>> Thanks
>> 
>> -Imran Amjad
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/how-to-translate-input-into-double-float-value-tf4611891.html#a13545254
Sent from the Tapestry - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


T5 Release date?

Posted by kranga <kr...@k2d2.org>.
Is there a new roadmap for the release of T5? The website says Fall 2007 and 
includes a note that the release has slipped ... 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: how to translate input into double/float value

Posted by Nick Westgate <ni...@key-planning.co.jp>.
You provide a translator. The framework provides one for Double etc:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/translator/

You can add more in your AppModule.java, like this ...
(I know this seems like overkill, but will likely be improved later.)

     // add a Float translator
     public static void contributeTranslatorDefaultSource(
         MappedConfiguration<Class<?>, Translator<?>> configuration)
     {
         configuration.add(Float.class, new Translator<Float>()
         {
             /**
              * Parses blank values to null, otherwise parses the client value to a float
              *
              * @throws ValidationException if the clientValue can not be parsed
              */
             public Float parseClient(String clientValue, Messages messages)
                 throws ValidationException
             {
                 if (InternalUtils.isBlank(clientValue))
                     return null;

                 try
                 {
                     Float result = new Float(clientValue.trim());
                     if (result.isInfinite())
                     {
                         throw new ValidationException(messages.format("number-range-exception",
                             clientValue));
                     }
                     return result;
                 }
                 catch (NumberFormatException ex)
                 {
                     throw new ValidationException(messages.format("number-format-exception",
                         clientValue));
                 }
             }

             /**
              * Converts null to the blank string, non-null to a string representation.
              */
             public String toClient(Float value)
             {
                 return value == null ? "" : value.toString();
             }
         });
     }

Cheers,
Nick.


Imran Amajd wrote:
> Hello,
> 
> Please guide me how i can translate input value into double or float. Thanks
> 
> -Imran Amjad

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org