[
https://issues.apache.org/jira/browse/TAPESTRY-817?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Jesse Kuhnert resolved TAPESTRY-817.
------------------------------------
Resolution: Fixed
Assignee: Jesse Kuhnert (was: Andreas Andreou)
> Translator for BigDecimal values
> --------------------------------
>
> Key: TAPESTRY-817
> URL: https://issues.apache.org/jira/browse/TAPESTRY-817
> Project: Tapestry
> Issue Type: New Feature
> Components: Framework
> Affects Versions: 4.0
> Reporter: Vjeran Marcinko
> Assigned To: Jesse Kuhnert
> 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.
-
You can reply to this email to add a comment to the issue online.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]