|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| package org.apache.tapestry.form; |
|
16 |
| |
|
17 |
| import org.apache.hivemind.service.ThreadLocale; |
|
18 |
| import org.apache.tapestry.IMarkupWriter; |
|
19 |
| import org.apache.tapestry.IRequestCycle; |
|
20 |
| import org.apache.tapestry.valid.IValidationDelegate; |
|
21 |
| import org.apache.tapestry.valid.ValidatorException; |
|
22 |
| |
|
23 |
| public class TranslatedFieldSupportImpl implements TranslatedFieldSupport |
|
24 |
| { |
|
25 |
| private ThreadLocale _threadLocale; |
|
26 |
| |
|
27 |
| |
|
28 |
| |
|
29 |
| |
|
30 |
0
| public ThreadLocale getThreadLocale()
|
|
31 |
| { |
|
32 |
0
| return _threadLocale;
|
|
33 |
| } |
|
34 |
| |
|
35 |
| |
|
36 |
| |
|
37 |
| |
|
38 |
| |
|
39 |
12
| public void setThreadLocale(ThreadLocale threadLocale)
|
|
40 |
| { |
|
41 |
12
| _threadLocale = threadLocale;
|
|
42 |
| } |
|
43 |
| |
|
44 |
6
| public String format(TranslatedField field, Object object)
|
|
45 |
| { |
|
46 |
6
| IValidationDelegate delegate = field.getForm().getDelegate();
|
|
47 |
| |
|
48 |
6
| return delegate.isInError() ? delegate.getFieldInputValue() : field.getTranslator().format(
|
|
49 |
| field, |
|
50 |
| _threadLocale.getLocale(), |
|
51 |
| object); |
|
52 |
| } |
|
53 |
| |
|
54 |
6
| public Object parse(TranslatedField field, String text) throws ValidatorException
|
|
55 |
| { |
|
56 |
6
| IValidationDelegate delegate = field.getForm().getDelegate();
|
|
57 |
| |
|
58 |
6
| delegate.recordFieldInputValue(text);
|
|
59 |
| |
|
60 |
6
| ValidationMessages messages = new ValidationMessagesImpl(field, _threadLocale.getLocale());
|
|
61 |
| |
|
62 |
6
| return field.getTranslator().parse(field, messages, text);
|
|
63 |
| } |
|
64 |
| |
|
65 |
6
| public void renderContributions(TranslatedField field, IMarkupWriter writer, IRequestCycle cycle)
|
|
66 |
| { |
|
67 |
6
| if (field.getForm().isClientValidationEnabled())
|
|
68 |
| { |
|
69 |
3
| FormComponentContributorContext context = new FormComponentContributorContextImpl(
|
|
70 |
| _threadLocale.getLocale(), cycle, field); |
|
71 |
| |
|
72 |
3
| field.getTranslator().renderContribution(writer, cycle, context, field);
|
|
73 |
| } |
|
74 |
| } |
|
75 |
| } |