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 |
8
| public void setThreadLocale(ThreadLocale threadLocale)
|
40 |
| { |
41 |
8
| _threadLocale = threadLocale;
|
42 |
| } |
43 |
| |
44 |
4
| public String format(TranslatedField field, Object object)
|
45 |
| { |
46 |
4
| IValidationDelegate delegate = field.getForm().getDelegate();
|
47 |
| |
48 |
4
| return delegate.isInError() ? delegate.getFieldInputValue() : field.getTranslator().format(
|
49 |
| field, |
50 |
| _threadLocale.getLocale(), |
51 |
| object); |
52 |
| } |
53 |
| |
54 |
4
| public Object parse(TranslatedField field, String text) throws ValidatorException
|
55 |
| { |
56 |
4
| IValidationDelegate delegate = field.getForm().getDelegate();
|
57 |
| |
58 |
4
| delegate.recordFieldInputValue(text);
|
59 |
| |
60 |
4
| ValidationMessages messages = new ValidationMessagesImpl(field, _threadLocale.getLocale());
|
61 |
| |
62 |
4
| return field.getTranslator().parse(field, messages, text);
|
63 |
| } |
64 |
| |
65 |
4
| public void renderContributions(TranslatedField field, IMarkupWriter writer, IRequestCycle cycle)
|
66 |
| { |
67 |
4
| if (field.getForm().isClientValidationEnabled())
|
68 |
| { |
69 |
2
| FormComponentContributorContext context = new FormComponentContributorContextImpl(
|
70 |
| _threadLocale.getLocale(), cycle, field); |
71 |
| |
72 |
2
| field.getTranslator().renderContribution(writer, cycle, context, field);
|
73 |
| } |
74 |
| } |
75 |
| } |