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/11/02 12:18:50 UTC

Re: how to translate input into double/float value

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