| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
package org.apache.tapestry5.internal.translator; |
| 16 | |
|
| 17 | |
import org.apache.tapestry5.Field; |
| 18 | |
import org.apache.tapestry5.MarkupWriter; |
| 19 | |
import org.apache.tapestry5.ValidationException; |
| 20 | |
import org.apache.tapestry5.services.FormSupport; |
| 21 | |
|
| 22 | |
import java.text.ParseException; |
| 23 | |
|
| 24 | |
|
| 25 | |
|
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | 162 | public class NumericTranslator<T extends Number> extends AbstractTranslator<T> |
| 31 | |
{ |
| 32 | |
private final NumericTranslatorSupport support; |
| 33 | |
|
| 34 | |
public NumericTranslator(String name, Class<T> type, NumericTranslatorSupport support) |
| 35 | |
{ |
| 36 | 144 | super(name, type, support.getMessageKey(type)); |
| 37 | |
|
| 38 | 144 | this.support = support; |
| 39 | 144 | } |
| 40 | |
|
| 41 | |
public void render(Field field, String message, MarkupWriter writer, FormSupport formSupport) |
| 42 | |
{ |
| 43 | 102 | if (formSupport.isClientValidationEnabled()) |
| 44 | 72 | support.addValidation(getType(), field, message); |
| 45 | 102 | } |
| 46 | |
|
| 47 | |
public T parseClient(Field field, String clientValue, String message) throws ValidationException |
| 48 | |
{ |
| 49 | |
try |
| 50 | |
{ |
| 51 | 74 | return support.parseClient(getType(), clientValue); |
| 52 | |
} |
| 53 | 14 | catch (ParseException ex) |
| 54 | |
{ |
| 55 | 14 | throw new ValidationException(message); |
| 56 | |
} |
| 57 | |
} |
| 58 | |
|
| 59 | |
public String toClient(T value) |
| 60 | |
{ |
| 61 | 88 | return support.toClient(getType(), value); |
| 62 | |
} |
| 63 | |
} |