tapestry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Andreas Andreou (JIRA)" <tapestry-...@jakarta.apache.org>
Subject [jira] Assigned: (TAPESTRY-817) Translator for BigDecimal values
Date Mon, 01 Jan 2007 18:33:27 GMT

     [ http://issues.apache.org/jira/browse/TAPESTRY-817?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Andreas Andreou reassigned TAPESTRY-817:
----------------------------------------

    Assignee: Andreas Andreou

> Translator for BigDecimal values
> --------------------------------
>
>                 Key: TAPESTRY-817
>                 URL: http://issues.apache.org/jira/browse/TAPESTRY-817
>             Project: Tapestry
>          Issue Type: New Feature
>          Components: Framework
>    Affects Versions: 4.0
>            Reporter: Vjeran Marcinko
>         Assigned To: Andreas Andreou
>             Fix For: 4.1.2
>
>
> Tapestry currently lacks Translator for BigDecimal values. NumberTranslator is no good
since it uses DecimalFormat underneath which converts String value into Double object, which
then cannot accurately be converted to BigDecimal by it's very nature.
> Solution is to introduce new BigDecimalTranslator, something like :
> import org.apache.hivemind.ApplicationRuntimeException;
> import org.apache.tapestry.form.IFormComponent;
> import org.apache.tapestry.form.ValidationMessages;
> import org.apache.tapestry.form.translator.AbstractTranslator;
> import org.apache.tapestry.valid.ValidationConstraint;
> import org.apache.tapestry.valid.ValidationStrings;
> import org.apache.tapestry.valid.ValidatorException;
> import java.math.BigDecimal;
> import java.util.Locale;
> public class BigDecimalTranslator extends AbstractTranslator {
>     public BigDecimalTranslator() {
>     }
>     // Needed until HIVEMIND-134 fix is available
>     public BigDecimalTranslator(String initializer) {
>         super(initializer);
>     }
>     protected String formatObject(IFormComponent field, Locale locale, Object object)
{
>         if (!(object instanceof BigDecimal)) {
>             throw new ApplicationRuntimeException("BigDecimalTranslator translates values
of type BigDecimal, not: " + object.getClass());
>         }
>         return object.toString();
>     }
>     protected Object parseText(IFormComponent field, ValidationMessages messages, String
text) throws ValidatorException {
>         try {
>             return new BigDecimal(text);
>         } catch (NumberFormatException e) {
>             throw new ValidatorException(buildMessage(messages, field, ValidationStrings.INVALID_NUMBER),
ValidationConstraint.NUMBER_FORMAT);
>         }
>     }
> }

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

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


Mime
View raw message