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 |
6 |
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 |
4 |
_threadLocale = threadLocale; |
46 |
4 |
} |
47 |
|
|
48 |
|
public String format(TranslatedField field, Object object) |
49 |
|
{ |
50 |
2 |
IValidationDelegate delegate = field.getForm().getDelegate(); |
51 |
|
|
52 |
2 |
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 |
2 |
IValidationDelegate delegate = field.getForm().getDelegate(); |
61 |
|
|
62 |
2 |
delegate.recordFieldInputValue(text); |
63 |
|
|
64 |
2 |
ValidationMessages messages = new ValidationMessagesImpl(field, _threadLocale.getLocale()); |
65 |
|
|
66 |
2 |
return field.getTranslator().parse(field, messages, text); |
67 |
|
} |
68 |
|
|
69 |
|
public void renderContributions(TranslatedField field, IMarkupWriter writer, IRequestCycle cycle) |
70 |
|
{ |
71 |
2 |
if (field.getForm().isClientValidationEnabled()) |
72 |
|
{ |
73 |
1 |
FormComponentContributorContext context = new FormComponentContributorContextImpl( |
74 |
|
_threadLocale.getLocale(), cycle, field); |
75 |
|
|
76 |
1 |
field.getTranslator().renderContribution(writer, cycle, context, field); |
77 |
|
} |
78 |
2 |
} |
79 |
|
} |