| 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 | 36 | public class Min extends AbstractValidator<Long, Number> |
| 25 | |
{ |
| 26 | |
public Min() |
| 27 | |
{ |
| 28 | 6 | super(Long.class, Number.class, "min-integer"); |
| 29 | 6 | } |
| 30 | |
|
| 31 | |
public void validate(Field field, Long constraintValue, MessageFormatter formatter, Number value) |
| 32 | |
throws ValidationException |
| 33 | |
{ |
| 34 | 16 | if (value.longValue() < constraintValue) |
| 35 | 4 | throw new ValidationException(buildMessage(formatter, field, constraintValue)); |
| 36 | 12 | } |
| 37 | |
|
| 38 | |
private String buildMessage(MessageFormatter formatter, Field field, Long constraintValue) |
| 39 | |
{ |
| 40 | 30 | return formatter.format(constraintValue, field.getLabel()); |
| 41 | |
} |
| 42 | |
|
| 43 | |
public void render(Field field, Long constraintValue, MessageFormatter formatter, MarkupWriter writer, |
| 44 | |
FormSupport formSupport) |
| 45 | |
{ |
| 46 | 26 | formSupport.addValidation(field, "min", buildMessage(formatter, field, constraintValue), constraintValue); |
| 47 | 26 | } |
| 48 | |
} |