Details

    • Type: New Feature
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 4.0
    • Fix Version/s: 4.1.2
    • Component/s: Framework
    • Labels:
      None

      Description

      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); }

      }
      }

        Attachments

          Activity

            People

            • Assignee:
              jkuhnert Jesse Kuhnert
              Reporter:
              vjeran@tis.hr Vjeran Marcinko
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: