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 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | 0 | public class TranslatedFieldSupportImpl implements TranslatedFieldSupport |
28 | |
{ |
29 | |
private ThreadLocale _threadLocale; |
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
public ThreadLocale getThreadLocale() |
35 | |
{ |
36 | 0 | return _threadLocale; |
37 | |
} |
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
public void setThreadLocale(ThreadLocale threadLocale) |
44 | |
{ |
45 | 0 | _threadLocale = threadLocale; |
46 | 0 | } |
47 | |
|
48 | |
public String format(TranslatedField field, Object object) |
49 | |
{ |
50 | 0 | IValidationDelegate delegate = field.getForm().getDelegate(); |
51 | |
|
52 | 0 | return delegate.isInError() ? delegate.getFieldInputValue() : field.getTranslator().format( |
53 | |
field, |
54 | |
_threadLocale.getLocale(), |
55 | |
object); |
56 | |
} |
57 | |
|
58 | |
public Object parse(TranslatedField field, String text) throws ValidatorException |
59 | |
{ |
60 | 0 | IValidationDelegate delegate = field.getForm().getDelegate(); |
61 | |
|
62 | 0 | delegate.recordFieldInputValue(text); |
63 | |
|
64 | 0 | ValidationMessages messages = new ValidationMessagesImpl(field, _threadLocale.getLocale()); |
65 | |
|
66 | 0 | return field.getTranslator().parse(field, messages, text); |
67 | |
} |
68 | |
|
69 | |
public void renderContributions(TranslatedField field, IMarkupWriter writer, IRequestCycle cycle) |
70 | |
{ |
71 | 0 | if (field.getForm().isClientValidationEnabled()) |
72 | |
{ |
73 | 0 | FormComponentContributorContext context = new FormComponentContributorContextImpl( |
74 | |
_threadLocale.getLocale(), cycle, field); |
75 | |
|
76 | 0 | field.getTranslator().renderContribution(writer, cycle, context, field); |
77 | |
} |
78 | 0 | } |
79 | |
} |