| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
package org.apache.tapestry5.validator; |
| 16 | |
|
| 17 | |
import org.apache.tapestry5.Field; |
| 18 | |
import org.apache.tapestry5.MarkupWriter; |
| 19 | |
import org.apache.tapestry5.ValidationException; |
| 20 | |
import org.apache.tapestry5.ioc.MessageFormatter; |
| 21 | |
import org.apache.tapestry5.services.FormSupport; |
| 22 | |
|
| 23 | |
|
| 24 | |
|
| 25 | |
|
| 26 | 22 | public class Max extends AbstractValidator<Long, Number> |
| 27 | |
{ |
| 28 | |
public Max() |
| 29 | |
{ |
| 30 | 6 | super(Long.class, Number.class, "max-integer"); |
| 31 | 6 | } |
| 32 | |
|
| 33 | |
public void validate(Field field, Long constraintValue, MessageFormatter formatter, Number value) |
| 34 | |
throws ValidationException |
| 35 | |
{ |
| 36 | 12 | if (value.longValue() > constraintValue) |
| 37 | 2 | throw new ValidationException(buildMessage(formatter, field, constraintValue)); |
| 38 | 10 | } |
| 39 | |
|
| 40 | |
private String buildMessage(MessageFormatter formatter, Field field, Long constraintValue) |
| 41 | |
{ |
| 42 | 20 | return formatter.format(constraintValue, field.getLabel()); |
| 43 | |
} |
| 44 | |
|
| 45 | |
public void render(Field field, Long constraintValue, MessageFormatter formatter, MarkupWriter writer, |
| 46 | |
FormSupport formSupport) |
| 47 | |
{ |
| 48 | 18 | formSupport.addValidation(field, "max", buildMessage(formatter, field, constraintValue), constraintValue); |
| 49 | 18 | } |
| 50 | |
|
| 51 | |
} |