NumberFormatter

2011-10-12 Thread Leon Derks
I have a TextField that shows a double value.

But I want to format the value in the Textfield as a decimal with 4 decimals 
(i.e. 0.1234)

In Tapestry there is a NumericFormatter and a BigDecimalNumericFormatter. But I 
can't find any documentation on how to use these on a TextField.
Can someone give me an example how I can format my double value into a decimal 
value with 4 decimals?

regards,
Leon



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



Re: NumberFormatter

2011-10-12 Thread derkoe

Leon Derks wrote:
 
 I have a TextField that shows a double value.
 
 But I want to format the value in the Textfield as a decimal with 4
 decimals (i.e. 0.1234)
 
 In Tapestry there is a NumericFormatter and a BigDecimalNumericFormatter.
 But I can't find any documentation on how to use these on a TextField.
 Can someone give me an example how I can format my double value into a
 decimal value with 4 decimals?
 
 regards,
 Leo
 

For input fields (such as TextField) you can add a parameter translate of
type FieldTranslator which translates between the object (e.g. BigDecimal)
and the String representation in the input.
See:
http://tapestry.apache.org/current/tapestry-core/ref/org/apache/tapestry5/corelib/components/TextField.html

You can also define your translator globally by contributing to
TranslatorSource.

-- 
Chris

--
View this message in context: 
http://tapestry.1045711.n5.nabble.com/NumberFormatter-tp4894812p4894939.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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



Re: NumberFormatter

2011-10-12 Thread Leon Derks
Hello Chris,

Thank you. Yes I have already seen that page, but I couldn't find an example 
with a FieldTranslator.
Does anyone have an example how to do this?

regards,
Leon


On Oct 12, 2011, at 11:57 AM, derkoe wrote:

 
 Leon Derks wrote:
 
 I have a TextField that shows a double value.
 
 But I want to format the value in the Textfield as a decimal with 4
 decimals (i.e. 0.1234)
 
 In Tapestry there is a NumericFormatter and a BigDecimalNumericFormatter.
 But I can't find any documentation on how to use these on a TextField.
 Can someone give me an example how I can format my double value into a
 decimal value with 4 decimals?
 
 regards,
 Leo
 
 
 For input fields (such as TextField) you can add a parameter translate of
 type FieldTranslator which translates between the object (e.g. BigDecimal)
 and the String representation in the input.
 See:
 http://tapestry.apache.org/current/tapestry-core/ref/org/apache/tapestry5/corelib/components/TextField.html
 
 You can also define your translator globally by contributing to
 TranslatorSource.
 
 -- 
 Chris
 
 --
 View this message in context: 
 http://tapestry.1045711.n5.nabble.com/NumberFormatter-tp4894812p4894939.html
 Sent from the Tapestry - User mailing list archive at Nabble.com.
 
 -
 To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
 For additional commands, e-mail: users-h...@tapestry.apache.org
 


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



Re: NumberFormatter

2011-10-12 Thread Muhammad Gelbana
When you need to contribute a configuration or anything to tapestry, first
check this page:
http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/services/TapestryModule.html

Find the method likely to satisfy your need, like in your case here:
http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/services/TapestryModule.html#contributeTranslatorSource(org.apache.tapestry5.ioc.MappedConfiguration,
org.apache.tapestry5.internal.translator.NumericTranslatorSupport)

Google it to see it in action:
http://www.google.com.eg/search?gcx=wsourceid=chromeie=UTF-8q=contributeTranslatorSource#sclient=psy-abhl=ensource=hpq=tapestry+%22contributeTranslatorSource%22pbx=1oq=tapestry+%22contributeTranslatorSource%22aq=faqi=aql=gs_sm=egs_upl=13088l14418l1l14680l2l3l0l0l0l0l0l0ll1l0bav=on.2,or.r_gc.r_pw.,cf.osbfp=127c72f3b5eca502biw=1366bih=643

Check those links too:
http://tapestryjava.blogspot.com/2008/09/tapestry-5-ioc-introducing-service.html
http://jumpstart.doublenegative.com.au/jumpstart/examples/input/translators1
http://jumpstart.doublenegative.com.au/jumpstart/examples/input/creatingtranslators1


Then love tapestry even more :)
 Good luck.

On Wed, Oct 12, 2011 at 12:04 PM, Leon Derks leon.de...@aurumeurope.comwrote:

 Hello Chris,

 Thank you. Yes I have already seen that page, but I couldn't find an
 example with a FieldTranslator.
 Does anyone have an example how to do this?

 regards,
 Leon


 On Oct 12, 2011, at 11:57 AM, derkoe wrote:

 
  Leon Derks wrote:
 
  I have a TextField that shows a double value.
 
  But I want to format the value in the Textfield as a decimal with 4
  decimals (i.e. 0.1234)
 
  In Tapestry there is a NumericFormatter and a
 BigDecimalNumericFormatter.
  But I can't find any documentation on how to use these on a TextField.
  Can someone give me an example how I can format my double value into a
  decimal value with 4 decimals?
 
  regards,
  Leo
 
 
  For input fields (such as TextField) you can add a parameter translate
 of
  type FieldTranslator which translates between the object (e.g.
 BigDecimal)
  and the String representation in the input.
  See:
 
 http://tapestry.apache.org/current/tapestry-core/ref/org/apache/tapestry5/corelib/components/TextField.html
 
  You can also define your translator globally by contributing to
  TranslatorSource.
 
  --
  Chris
 
  --
  View this message in context:
 http://tapestry.1045711.n5.nabble.com/NumberFormatter-tp4894812p4894939.html
  Sent from the Tapestry - User mailing list archive at Nabble.com.
 
  -
  To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
  For additional commands, e-mail: users-h...@tapestry.apache.org
 


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




-- 
*Regards,*
*Muhammad Gelbana
Java Developer*


Re: NumberFormatter

2011-10-12 Thread Leon Derks
Hello all,
Thanks for your support.

It was quite some work, but I managed to get it working..
For everybody else who is struggling with this, here is my code for Tapestry 
5.2.6

Page.tml
input type=text t:type=textfield t:id=currencyInput 
t:validate=required value=price translate=currency /

CurrencyTranslator.java
import java.text.DecimalFormat;

import org.apache.tapestry5.Field;
import org.apache.tapestry5.MarkupWriter;
import org.apache.tapestry5.ValidationException;
import org.apache.tapestry5.internal.translator.AbstractTranslator;
import org.apache.tapestry5.services.FormSupport;

public class CurrencyTranslator extends AbstractTranslatorDouble {

private static DecimalFormat decimalFormat = new 
DecimalFormat(0.);

public CurrencyTranslator() {
super(currency, Double.class, currency-format-exception);
}

@Override
public String toClient(Double value) {
return decimalFormat.format(value);
}

@Override
public Double parseClient(Field field, String clientValue, String 
message) throws ValidationException {
Double returnValue = null;

if(clientValue != null) {
try{
returnValue =  Double.valueOf(clientValue);
}
catch(Exception e) {
throw new ValidationException(message);
}
}

return returnValue;
}

@Override
public void render(Field field, String message, MarkupWriter writer, 
FormSupport formSupport) {
}

}

AppModule.java
public static void contributeTranslatorSource(MappedConfigurationClass, 
Translator configuration) {
configuration.override(Double.class, new CurrencyTranslator());
 }


On Oct 12, 2011, at 12:34 PM, Muhammad Gelbana wrote:

 When you need to contribute a configuration or anything to tapestry, first
 check this page:
 http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/services/TapestryModule.html
 
 Find the method likely to satisfy your need, like in your case here:
 http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/services/TapestryModule.html#contributeTranslatorSource(org.apache.tapestry5.ioc.MappedConfiguration,
 org.apache.tapestry5.internal.translator.NumericTranslatorSupport)
 
 Google it to see it in action:
 http://www.google.com.eg/search?gcx=wsourceid=chromeie=UTF-8q=contributeTranslatorSource#sclient=psy-abhl=ensource=hpq=tapestry+%22contributeTranslatorSource%22pbx=1oq=tapestry+%22contributeTranslatorSource%22aq=faqi=aql=gs_sm=egs_upl=13088l14418l1l14680l2l3l0l0l0l0l0l0ll1l0bav=on.2,or.r_gc.r_pw.,cf.osbfp=127c72f3b5eca502biw=1366bih=643
 
 Check those links too:
 http://tapestryjava.blogspot.com/2008/09/tapestry-5-ioc-introducing-service.html
 http://jumpstart.doublenegative.com.au/jumpstart/examples/input/translators1
 http://jumpstart.doublenegative.com.au/jumpstart/examples/input/creatingtranslators1
 
 
 Then love tapestry even more :)
 Good luck.
 
 On Wed, Oct 12, 2011 at 12:04 PM, Leon Derks 
 leon.de...@aurumeurope.comwrote:
 
 Hello Chris,
 
 Thank you. Yes I have already seen that page, but I couldn't find an
 example with a FieldTranslator.
 Does anyone have an example how to do this?
 
 regards,
 Leon
 
 
 On Oct 12, 2011, at 11:57 AM, derkoe wrote:
 
 
 Leon Derks wrote:
 
 I have a TextField that shows a double value.
 
 But I want to format the value in the Textfield as a decimal with 4
 decimals (i.e. 0.1234)
 
 In Tapestry there is a NumericFormatter and a
 BigDecimalNumericFormatter.
 But I can't find any documentation on how to use these on a TextField.
 Can someone give me an example how I can format my double value into a
 decimal value with 4 decimals?
 
 regards,
 Leo
 
 
 For input fields (such as TextField) you can add a parameter translate
 of
 type FieldTranslator which translates between the object (e.g.
 BigDecimal)
 and the String representation in the input.
 See:
 
 http://tapestry.apache.org/current/tapestry-core/ref/org/apache/tapestry5/corelib/components/TextField.html
 
 You can also define your translator globally by contributing to
 TranslatorSource.
 
 --
 Chris
 
 --
 View this message in context:
 http://tapestry.1045711.n5.nabble.com/NumberFormatter-tp4894812p4894939.html
 Sent from the Tapestry - User mailing list archive at Nabble.com.
 
 -
 To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
 For additional commands, e-mail: users-h...@tapestry.apache.org
 
 
 
 -
 To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
 For additional commands, e-mail: users-h...@tapestry.apache.org
 
 
 
 
 -- 
 *Regards,*
 *Muhammad Gelbana