tapestry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jochen Kemnade (JIRA)" <j...@apache.org>
Subject [jira] [Closed] (TAP5-1947) BigDecimal Validator
Date Mon, 22 Aug 2016 06:48:22 GMT

     [ https://issues.apache.org/jira/browse/TAP5-1947?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Jochen Kemnade closed TAP5-1947.
--------------------------------
    Resolution: Incomplete

We assume this is no longer relevant and therefore close it.
If you still have this issue in a recent Tapestry version (such as 5.4.1 or newer), feel free
to provide the necessary information and reopen.

> BigDecimal Validator
> --------------------
>
>                 Key: TAP5-1947
>                 URL: https://issues.apache.org/jira/browse/TAP5-1947
>             Project: Tapestry 5
>          Issue Type: Improvement
>          Components: tapestry-core
>    Affects Versions: 5.3.3
>            Reporter: George Christman
>            Priority: Minor
>              Labels: bulk-close-candidate
>
> Tapestry should offer the ability to validate BigDecimal max length's for currency/amounts.
I'm donating the following code which validates maxScale and maxPrecision. Unfortunately,
I haven't written anything to handle the clientside validation. 
> //app.properties
> maximum-precision=You may provide at most %d numbers for %s.
> maximum-scale=You may provide at most %d decimal digits for %s.
> //MaxScale
> public class MaxScale extends AbstractValidator<Integer, BigDecimal> {
>     public MaxScale() {
>         super(Integer.class, BigDecimal.class, "maximum-scale");
>     }
>     @Override
>     public void validate(Field field, Integer constraintValue, MessageFormatter formatter,
BigDecimal value)
>             throws ValidationException
>     {        
>         if (value.scale() > constraintValue)
>             throw new ValidationException(buildMessage(formatter, field, constraintValue));
>     }
>     private String buildMessage(MessageFormatter formatter, Field field, Integer constraintValue)
{
>         return formatter.format(constraintValue, field.getLabel());
>     }
>    
>     @Override
>     public void render(Field field, Integer constraintValue, MessageFormatter formatter,
MarkupWriter writer,
>             FormSupport formSupport) {
>         formSupport.addValidation(field, "maxscale", buildMessage(formatter, field, constraintValue),
constraintValue);
>     }
> }
> //MaxPrecision
> public class MaxPrecision extends AbstractValidator<Integer, BigDecimal> {
>     public MaxPrecision() {
>         super(Integer.class, BigDecimal.class, "maximum-precision");
>     }
>     @Override
>     public void validate(Field field, Integer constraintValue, MessageFormatter formatter,
BigDecimal value)
>             throws ValidationException
>     {        
>         if (value.precision() > constraintValue)
>             throw new ValidationException(buildMessage(formatter, field, constraintValue));
>     }
>     private String buildMessage(MessageFormatter formatter, Field field, Integer constraintValue)
{
>         return formatter.format(constraintValue, field.getLabel());
>     }
>    
>     @Override
>     public void render(Field field, Integer constraintValue, MessageFormatter formatter,
MarkupWriter writer,
>             FormSupport formSupport) {
>         formSupport.addValidation(field, "maxprecision", buildMessage(formatter, field,
constraintValue), constraintValue);
>     }
> }
> //AppModule
>     @SuppressWarnings("rawtypes")
>     public static void contributeFieldValidatorSource(MappedConfiguration<String,
Validator> configuration) {
>         configuration.add("maxScale", new MaxScale());
>         configuration.add("maxPrecision", new MaxPrecision());
>     } 



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message