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( MappedConfigurationClass?, Translator? configuration) { configuration.add(Float.class, new TranslatorFloat() { /** * 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: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- 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: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
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: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: how to translate input into double/float value
Nick, For a PropertySelection component housing strings... am I free to perform OGNL arithmetic on those elements if they happen to be numeric strings? I am wondering if I need a translator or if it is illegal to perform ognl arithmetic on PropertySelection strings that happen to be 1, or 2.. Best regards Ken in nashua _ Boo! Scare away worms, viruses and so much more! Try Windows Live OneCare! http://onecare.live.com/standard/en-us/purchase/trial.aspx?s_cid=wl_hotmailnews
Re: how to translate input into double/float value
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( MappedConfigurationClass?, Translator? configuration) { configuration.add(Float.class, new TranslatorFloat() { /** * 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: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]