You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Benny Law <be...@gmail.com> on 2009/11/17 23:12:22 UTC

Number Formatting in TextField (T5)

I am having some difficulty finding documentation and examples on how to
control the formatting of numbers in TextField components. I have a page
where I use two TextFields to display the latitude and longitude of a GPS
location in decimal degrees. The default formatting provided by Tapestry
only displays 3 decimal places, but I need 5.

My current thinking is that I would need to create a Translator to use with
these TextFields. Using the toClient event doesn't make sense because it's
not reusable.

Is there a simpler way to do this, i.e. specify formatting for TextField? If
custom Translators is the way to go, has anyone built something for numbers
that reflects the current locale?

Thanks,

Benny

Re: Number Formatting in TextField (T5)

Posted by Ville Virtanen <vi...@cerion.fi>.
Hi,

we actually made it the hard way and currently we have our own
BigDecimalFieldTranslatorImpl, which takes care of the actual validation, as
seen here:

public class BigDecimalFieldTranslatorImpl extends
FieldTranslatorImpl<BigDecimal> {

    private final Locale locale;
    private final int numberOfDecimals;
    private final Field field;
    private final MessageFormatter messageFormatter;
    private final Messages messages;
    private final boolean useGrouping;

    public BigDecimalFieldTranslatorImpl(int numberOfDecimals, boolean
useGrouping, Locale locale, Field field, Translator<BigDecimal> translator,
MessageFormatter formatter, FormSupport formSupport, Messages messages) {
        super(field, translator, formatter, formSupport);
        this.locale = locale;
        this.numberOfDecimals = numberOfDecimals;
        this.field = field;
        this.messageFormatter = formatter;
        this.messages = messages;
        this.useGrouping = useGrouping;
    }

    @Override
    public String toClient(BigDecimal value)
    {
        if(useGrouping){
            return NumberFormatUtility.formatWithGrouping(value,
numberOfDecimals, locale);
        }
        return NumberFormatUtility.format(value, numberOfDecimals, locale);
    }

    @Override
    public BigDecimal parse(String input) throws ValidationException {

		if(input != null) {
			input = input.replaceAll("\\s", "");
		}

        BigDecimal result = super.parse(input);

        if(NumberFormatUtility.hasTooManyDecimals(input, numberOfDecimals,
locale)) {
            throw new ValidationException(formatMessage());
        }

        return result;
    }

    private String formatMessage()
    {
        if(numberOfDecimals == 0) {
            return messages.format("integer-format-exception",
field.getLabel());
        } else {
            return
messages.format("fi.cerion.common.too-many-decimal-places",
field.getLabel(), numberOfDecimals);
        }
    }

}

However, to supply per field validation data to the validator we opted to
make our own service that is used to get the field translator:
public class CerionFieldTranslatorSourceImpl implements
CerionFieldTranslatorSource {

    private final PersistentLocale persistentLocale;
    private final TranslatorSource translatorSource;
    private final FieldTranslatorSource fieldTranslatorSource;
    private final ValidationMessagesSource validationMessagesSource;
    private final FormSupport formSupport;

    public CerionFieldTranslatorSourceImpl(PersistentLocale
persistentLocale, TranslatorSource translatorSource, FieldTranslatorSource
fieldTranslatorSource, ValidationMessagesSource validationMessagesSource,
FormSupport formSupport) {
        this.persistentLocale = persistentLocale;
        this.translatorSource = translatorSource;
        this.fieldTranslatorSource = fieldTranslatorSource;
        this.validationMessagesSource = validationMessagesSource;
        this.formSupport = formSupport;
    }

    @Override
    public FieldTranslator<BigDecimal> createBigDecimalTranslator(Field
field, int numberOfDecimals)
    {
        ComponentResources resources =
((ComponentResourcesAware)field).getComponentResources();
        Translator translator =
translatorSource.getByType(BigDecimal.class);

        return createTranslator(field, resources.getId(),
resources.getContainerMessages(), resources.getLocale(), translator,
numberOfDecimals, false);
    }

    @Override
    public FieldTranslator<BigDecimal> createBigDecimalTranslator(Field
field, int numberOfDecimals, boolean useGrouping)
    {
        ComponentResources resources =
((ComponentResourcesAware)field).getComponentResources();
        Translator translator =
translatorSource.getByType(BigDecimal.class);

        return createTranslator(field, resources.getId(),
resources.getContainerMessages(), resources.getLocale(), translator,
numberOfDecimals, useGrouping);
    }

    private FieldTranslator createTranslator(Field field, String overrideId,
Messages overrideMessages, Locale locale, Translator translator, int
numberOfDecimals, boolean useGrouping)
    {
        MessageFormatter formatter = findFormatter(overrideId,
overrideMessages, locale, translator);
        return new BigDecimalFieldTranslatorImpl(numberOfDecimals,
useGrouping, locale, field, translator, formatter, formSupport,
overrideMessages);
    }

    private MessageFormatter findFormatter(String overrideId, Messages
overrideMessages, Locale locale,
                                           Translator translator)
    {
        // TAP5-228: Try to distinguish message overrides by form id and
overrideId (i.e., property name) first.

        String translatorName = translator.getName();

        String overrideKey = formSupport.getFormValidationId() + "-" +
overrideId + "-" + translatorName + "-message";

        if (overrideMessages.contains(overrideKey))
            return overrideMessages.getFormatter(overrideKey);

        // Ok, look for a simpler name that omits the formId prefix.

        overrideKey = overrideId + "-" + translatorName + "-message";

        if (overrideMessages.contains(overrideKey))
            return overrideMessages.getFormatter(overrideKey);

        // Otherwise, use the built-in validation message appropriate to
this validator.

        Messages validationMessages =
validationMessagesSource.getValidationMessages(locale);

        return validationMessages.getFormatter(translator.getMessageKey());
    }

}

Then we just use it to get the desired translator. Our system (form
templating engine) is constructed so that every field requiring this is
added in a single location, so this code is good enough for our use case.

Anyway, I really would like to see your solutions: How to supply arbitrary
per field validation data to custom validators when you need to also use the
per field validation data to construct the validation error message?

One example of this is how to tell the user in error message how many
characters is the max limit in the field and how many characters she/he has
typed. E.g. "Product description is 3072 characters long but the maximum
length is 3000 characters. Please edit your text accordingly."

 - Ville



Bryan Lewis-5 wrote:
> 
> Thanks, that's what I was missing!!  A translator can be supplied as a
> page
> property for per-field use!
> One doesn't need to contribute a custom translator in AppModule unless one
> wants it to apply universally to a custom type and wants to avoid
> repeatedly
> specifying the "translate".
> 
> It would be good to clarify this in the docs.  I don't see it described
> anywhere; I see only examples of the contributed-custom-type case.  (And
> it's different from the way Tapestry 3 and 4 did it.)
> 
> 
> Details:  In the tml:
> 
> <t:textfield t:id="annualSales" value="company.annualSales"
> translate="prop:currency"/>
> 
> In the java (actually in my Page super-class):
> 
>     public FieldTranslator<BigDecimal> getCurrency()
>     {
>         return new CurrencyTranslator();
>     }
> 
> Where CurrencyTranslator implements FieldTranslator<BigDecimal>.
> 
> 
> 
> On Sun, Dec 27, 2009 at 3:37 PM, Thiago H. de Paula Figueiredo <
> thiagohp@gmail.com> wrote:
> 
>> Em Sun, 27 Dec 2009 17:58:07 -0200, Bryan Lewis <jb...@gmail.com>
>> escreveu:
>>
>>  Really?  I wish that was my experience.  Here's what I'm seeing; maybe
>> you
>>> can point out what I've done wrong.
>>> <t:textfield t:id="annualSales" value="company.annualSales"
>>> t:translate="bigdecimal"/>
>>>
>>
>> Have you tried t:translate="prop:salesTranslator" and a Translator
>> getSalesTranslator() in your class?
>>
>> TapestryModule already creates a translator for BigDecimal, so I guess
>> yours is ignored. I agree that the source of translators should be
>> improved.
>>
>>
>> --
>> Thiago H. de Paula Figueiredo
>> Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,
>> and instructor
>> Owner, software architect and developer, Ars Machina Tecnologia da
>> Informação Ltda.
>> http://www.arsmachina.com.br
>>
>> ---------------------------------------------------------------------
>> 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://old.nabble.com/Number-Formatting-in-TextField-%28T5%29-tp26398708p27009963.html
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: Number Formatting in TextField (T5)

Posted by Bryan Lewis <jb...@gmail.com>.
Thanks, that's what I was missing!!  A translator can be supplied as a page
property for per-field use!
One doesn't need to contribute a custom translator in AppModule unless one
wants it to apply universally to a custom type and wants to avoid repeatedly
specifying the "translate".

It would be good to clarify this in the docs.  I don't see it described
anywhere; I see only examples of the contributed-custom-type case.  (And
it's different from the way Tapestry 3 and 4 did it.)


Details:  In the tml:

<t:textfield t:id="annualSales" value="company.annualSales"
translate="prop:currency"/>

In the java (actually in my Page super-class):

    public FieldTranslator<BigDecimal> getCurrency()
    {
        return new CurrencyTranslator();
    }

Where CurrencyTranslator implements FieldTranslator<BigDecimal>.



On Sun, Dec 27, 2009 at 3:37 PM, Thiago H. de Paula Figueiredo <
thiagohp@gmail.com> wrote:

> Em Sun, 27 Dec 2009 17:58:07 -0200, Bryan Lewis <jb...@gmail.com>
> escreveu:
>
>  Really?  I wish that was my experience.  Here's what I'm seeing; maybe you
>> can point out what I've done wrong.
>> <t:textfield t:id="annualSales" value="company.annualSales"
>> t:translate="bigdecimal"/>
>>
>
> Have you tried t:translate="prop:salesTranslator" and a Translator
> getSalesTranslator() in your class?
>
> TapestryModule already creates a translator for BigDecimal, so I guess
> yours is ignored. I agree that the source of translators should be improved.
>
>
> --
> Thiago H. de Paula Figueiredo
> Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,
> and instructor
> Owner, software architect and developer, Ars Machina Tecnologia da
> Informação Ltda.
> http://www.arsmachina.com.br
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: Number Formatting in TextField (T5)

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
Em Sun, 27 Dec 2009 17:58:07 -0200, Bryan Lewis <jb...@gmail.com>  
escreveu:

> Really?  I wish that was my experience.  Here's what I'm seeing; maybe  
> you can point out what I've done wrong.
> <t:textfield t:id="annualSales" value="company.annualSales"
> t:translate="bigdecimal"/>

Have you tried t:translate="prop:salesTranslator" and a Translator  
getSalesTranslator() in your class?

TapestryModule already creates a translator for BigDecimal, so I guess  
yours is ignored. I agree that the source of translators should be  
improved.

-- 
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,  
and instructor
Owner, software architect and developer, Ars Machina Tecnologia da  
Informação Ltda.
http://www.arsmachina.com.br

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


Re: Number Formatting in TextField (T5)

Posted by Bryan Lewis <jb...@gmail.com>.
Thiago wrote:

>
> As of 5.1.0.5, it isn't possible to override them for a given type
> globally, but you can override it in a given TextField instance (translate
> parameter).
>
>
Really?  I wish that was my experience.  Here's what I'm seeing; maybe you
can point out what I've done wrong.

I have a custom BigDecimal translator that formats the number as a
currency.  (Code outlined below in case it matters.)

A page has a couple of textfields, one specifying t:translate and one not:

<t:textfield t:id="annualSales" value="company.annualSales"
t:translate="bigdecimal"/>
<t:textfield t:id="averageAr" value="company.averageAr"/>

The result is that both textfields use the custom translator, as verified in
the debugger and by looking at the resulting page.  Why should the textfield
without the t:translate get the custom translator?  Should I specify some
other t:translate to prevent that?

The other problem I had, when I first upgraded to 5.1.0.5, was that my
translator didn't always take effect.  After some restarts, Tapestry's
built-in BigDecimalNumericFormatter would be supplied.  There was a thread
about this; see
http://old.nabble.com/overriding-a-translator-ts25791006.html



Details:  The essentials of the translator:

  public class BigDecimalTranslator extends AbstractTranslator<BigDecimal>
  {
    public BigDecimalTranslator() {
        super("bigdecimal", BigDecimal.class,
"bigdecimal-format-exception");
    }
    public BigDecimal parseClient(Field field, String clientValue, String
message) throws ValidationException {
        // ...
    }
    public void render(Field field, String message, MarkupWriter writer,
FormSupport formSupport) {
        // Do nothing; we don't support client-side validation.
    }
    /** Returns a string formatted as a currency. */
    public String toClient(BigDecimal number) {
        // ...
    }
  }

AppModule adds it:

    public static void contributeTranslatorSource(Configuration<Translator>
configuration) {
        configuration.add(new BigDecimalTranslator());
    }

Re: Number Formatting in TextField (T5)

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
Em Sun, 27 Dec 2009 12:43:29 -0200, Bryan Lewis <jb...@gmail.com>  
escreveu:

> I'd like to see either or both of the techniques.

Me too. It's nice to have some different approaches to the same problem  
and them pick the one that suits better a given scenario.

> I thought that it wasn't
> possible to override Tapestry's built-in translators.  (See TAP-725, "You
> cannot define two different translators for a single field type.")

As of 5.1.0.5, it isn't possible to override them for a given type  
globally, but you can override it in a given TextField instance (translate  
parameter).

-- 
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,  
and instructor
Owner, software architect and developer, Ars Machina Tecnologia da  
Informação Ltda.
http://www.arsmachina.com.br

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


Re: Number Formatting in TextField (T5)

Posted by Bryan Lewis <jb...@gmail.com>.
I'd like to see either or both of the techniques.  I thought that it wasn't
possible to override Tapestry's built-in translators.  (See TAP-725, "You
cannot define two different translators for a single field type.")  When I
tried to add custom translators for String and BigDecimal types, either my
translator got ignored or it got applied to all properties of that type.
I'd love to hear that I'm missing something.


On Sun, Dec 27, 2009 at 9:02 AM, Ville Virtanen <vi...@cerion.fi>wrote:

>
> Hi!
>
> If you get this working please share the results. This is something I never
> thought when adding our number format handling. (Which is based on custom
> translators. I'm happy to share the current solution if you are
> interested?)
>
>  - Ville
>
>
> Benny Law wrote:
> >
> > On Thu, Dec 24, 2009 at 5:41 AM, Thiago H. de Paula Figueiredo <
> > thiagohp@gmail.com> wrote:
> >
> >>
> >> This is very clever! I guess it'll work. :) Just pay attention that the
> >> parameter received by the translate is a FieldTranslator, not a
> >> Translator
> >> itself.
> >>
> >> Thanks Thiago. I already found out the hard way, but it's basically
> >> working
> > now :) The last thing I still need to figure out is the purpose of
> > FieldTranslator (I read the doc but still didn't fully get it) and how I
> > can
> > allow the error messages to be overridden in the message catalogue on a
> > per
> > field basis in the standard manner. I guess I need to use some other
> > service
> > to do that. Any hint will be appreciated :)
> >
> >
>
> --
> View this message in context:
> http://old.nabble.com/Number-Formatting-in-TextField-%28T5%29-tp26398708p26934138.html
> 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: Number Formatting in TextField (T5)

Posted by Ville Virtanen <vi...@cerion.fi>.
Hi!

If you get this working please share the results. This is something I never
thought when adding our number format handling. (Which is based on custom
translators. I'm happy to share the current solution if you are interested?)

 - Ville


Benny Law wrote:
> 
> On Thu, Dec 24, 2009 at 5:41 AM, Thiago H. de Paula Figueiredo <
> thiagohp@gmail.com> wrote:
> 
>>
>> This is very clever! I guess it'll work. :) Just pay attention that the
>> parameter received by the translate is a FieldTranslator, not a
>> Translator
>> itself.
>>
>> Thanks Thiago. I already found out the hard way, but it's basically
>> working
> now :) The last thing I still need to figure out is the purpose of
> FieldTranslator (I read the doc but still didn't fully get it) and how I
> can
> allow the error messages to be overridden in the message catalogue on a
> per
> field basis in the standard manner. I guess I need to use some other
> service
> to do that. Any hint will be appreciated :)
> 
> 

-- 
View this message in context: http://old.nabble.com/Number-Formatting-in-TextField-%28T5%29-tp26398708p26934138.html
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: Number Formatting in TextField (T5)

Posted by Benny Law <be...@gmail.com>.
On Thu, Dec 24, 2009 at 5:41 AM, Thiago H. de Paula Figueiredo <
thiagohp@gmail.com> wrote:

>
> This is very clever! I guess it'll work. :) Just pay attention that the
> parameter received by the translate is a FieldTranslator, not a Translator
> itself.
>
> Thanks Thiago. I already found out the hard way, but it's basically working
now :) The last thing I still need to figure out is the purpose of
FieldTranslator (I read the doc but still didn't fully get it) and how I can
allow the error messages to be overridden in the message catalogue on a per
field basis in the standard manner. I guess I need to use some other service
to do that. Any hint will be appreciated :)

Re: Number Formatting in TextField (T5)

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
Em Thu, 24 Dec 2009 01:09:03 -0200, Benny Law <be...@gmail.com>  
escreveu:

> Hi Thiago,

Hi!

> I just thought of another idea and would like to bounce it off you.  
> Instead of subclassing AbstractTextField to create NumericField, I can  
> just use
> TextField as is, but define a new binding prefix for the translate  
> parameter
> which will allow the format pattern to be specified as the binding
> expression, like this:
>
> <t:textfield t:id="latitude" translate="numberformat:0.00000" />

This is very clever! I guess it'll work. :) Just pay attention that the  
parameter received by the translate is a FieldTranslator, not a Translator  
itself.

-- 
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,  
and instructor
Owner, software architect and developer, Ars Machina Tecnologia da  
Informação Ltda.
http://www.arsmachina.com.br

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


Re: Number Formatting in TextField (T5)

Posted by Benny Law <be...@gmail.com>.
Hi Thiago,

I just thought of another idea and would like to bounce it off you. Instead
of subclassing AbstractTextField to create NumericField, I can just use
TextField as is, but define a new binding prefix for the translate parameter
which will allow the format pattern to be specified as the binding
expression, like this:

<t:textfield t:id="latitude" translate="numberformat:0.00000" />

I will need to create a new BindingFactory to return a numeric translator
that uses the specified format.

What do you think? Will this work?

Benny

On Wed, Dec 23, 2009 at 11:32 AM, Thiago H. de Paula Figueiredo <
thiagohp@gmail.com> wrote:

> Em Wed, 23 Dec 2009 14:01:03 -0200, Benny Law <be...@gmail.com>
> escreveu:
>
>  Hi Thiago,
>>
>
> Hi!
>
>
>  should be displayed. Where I got lost is figuring out how to provide the
>> custom translator from within NumericField.
>>
>
> In this case, I think it would be easier to not use a translator and do the
> conversion yourself.
>
>
> --
> Thiago H. de Paula Figueiredo
> Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,
> and instructor
> Owner, software architect and developer, Ars Machina Tecnologia da
> Informação Ltda.
> http://www.arsmachina.com.br
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: Number Formatting in TextField (T5)

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
Em Wed, 23 Dec 2009 14:01:03 -0200, Benny Law <be...@gmail.com>  
escreveu:

> Hi Thiago,

Hi!

> should be displayed. Where I got lost is figuring out how to provide the
> custom translator from within NumericField.

In this case, I think it would be easier to not use a translator and do  
the conversion yourself.

-- 
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,  
and instructor
Owner, software architect and developer, Ars Machina Tecnologia da  
Informação Ltda.
http://www.arsmachina.com.br

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


Re: Number Formatting in TextField (T5)

Posted by Benny Law <be...@gmail.com>.
Hi Thiago,

I finally got some time to revisit this. I spent some time last night trying
to subclass AbstractTextField as you suggested, but got lost. I would
appreciate it if you or anybody else could give me some pointers. What I am
trying to do is to create a NumericField by extending AbstractTextField and
adding a format parameter which accepts a decimal format pattern. Using this
pattern string, NumericField will provide a translator based on that
pattern. Again, the motivation behind this is so that I can control
precisely how many decimal places to display and whether group separators
should be displayed. Where I got lost is figuring out how to provide the
custom translator from within NumericField.

Thanks in advance,

Benny

On Wed, Nov 18, 2009 at 8:11 PM, Thiago H. de Paula Figueiredo <
thiagohp@gmail.com> wrote:

> Em Wed, 18 Nov 2009 22:02:42 -0200, Benny Law <be...@gmail.com>
> escreveu:
>
>
>  If I need to implement it myself, I would like  to
>> know how best to provide this info to the translator on a per field basis.
>>
>
> AFAIK, it's not possible.
>
>
>  Should I create a NumericField component (subclass of TextField) and add
>> parameters for this?
>>
>
> Sublass AbstractTextField instead.
>
>
> --
> Thiago H. de Paula Figueiredo
> Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,
> and instructor
> Owner, software architect and developer, Ars Machina Tecnologia da
> Informação Ltda.
> http://www.arsmachina.com.br
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: Number Formatting in TextField (T5)

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
Em Wed, 18 Nov 2009 22:02:42 -0200, Benny Law <be...@gmail.com>  
escreveu:

> If I need to implement it myself, I would like  to
> know how best to provide this info to the translator on a per field  
> basis.

AFAIK, it's not possible.

> Should I create a NumericField component (subclass of TextField) and add
> parameters for this?

Sublass AbstractTextField instead.

-- 
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,  
and instructor
Owner, software architect and developer, Ars Machina Tecnologia da  
Informação Ltda.
http://www.arsmachina.com.br

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


Re: Number Formatting in TextField (T5)

Posted by Benny Law <be...@gmail.com>.
Thanks Thiago. I was hoping that someone had already implemented a generic
numeric translator that allowed formatting to be specified at the field
level, e.g. number of decimal places, whether or not thousands separators
should be displayed, etc. If I need to implement it myself, I would like to
know how best to provide this info to the translator on a per field basis.
Should I create a NumericField component (subclass of TextField) and add
parameters for this?

Benny

On Tue, Nov 17, 2009 at 5:37 PM, Thiago H. de Paula Figueiredo <
thiagohp@gmail.com> wrote:

> Em Tue, 17 Nov 2009 20:12:22 -0200, Benny Law <be...@gmail.com>
> escreveu:
>
>
>  Is there a simpler way to do this, i.e. specify formatting for TextField?
>> If custom Translators is the way to go, has anyone built something for
>> numbers that reflects the current locale?
>>
>
> Implement your own translator, as it probably will be used in many places
> in your application.
>
> --
> Thiago H. de Paula Figueiredo
> Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,
> and instructor
> Owner, software architect and developer, Ars Machina Tecnologia da
> Informação Ltda.
> http://www.arsmachina.com.br
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: Number Formatting in TextField (T5)

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
Em Tue, 17 Nov 2009 20:12:22 -0200, Benny Law <be...@gmail.com>  
escreveu:

> Is there a simpler way to do this, i.e. specify formatting for  
> TextField? If custom Translators is the way to go, has anyone built  
> something for numbers that reflects the current locale?

Implement your own translator, as it probably will be used in many places  
in your application.

-- 
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,  
and instructor
Owner, software architect and developer, Ars Machina Tecnologia da  
Informação Ltda.
http://www.arsmachina.com.br

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