1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
package org.apache.tapestry.form; |
16 |
|
|
17 |
|
import java.util.Locale; |
18 |
|
|
19 |
|
import org.apache.hivemind.ClassResolver; |
20 |
|
import org.apache.hivemind.Resource; |
21 |
|
import org.apache.hivemind.util.ClasspathResource; |
22 |
|
import org.apache.tapestry.IComponent; |
23 |
|
import org.apache.tapestry.IForm; |
24 |
|
import org.apache.tapestry.IRequestCycle; |
25 |
|
import org.apache.tapestry.PageRenderSupport; |
26 |
|
import org.apache.tapestry.TapestryUtils; |
27 |
|
import org.apache.tapestry.json.JSONObject; |
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
public class FormComponentContributorContextImpl extends ValidationMessagesImpl implements |
36 |
|
FormComponentContributorContext |
37 |
|
{ |
38 |
|
private final ClassResolver _resolver; |
39 |
|
|
40 |
|
private final PageRenderSupport _pageRenderSupport; |
41 |
|
|
42 |
|
private final IFormComponent _field; |
43 |
|
|
44 |
|
private final IForm _form; |
45 |
|
|
46 |
|
private final String _formId; |
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
FormComponentContributorContextImpl(IFormComponent field) |
53 |
|
{ |
54 |
0 |
super(field, Locale.ENGLISH); |
55 |
|
|
56 |
0 |
_field = field; |
57 |
0 |
_resolver = null; |
58 |
0 |
_formId = null; |
59 |
0 |
_pageRenderSupport = null; |
60 |
0 |
_form = null; |
61 |
0 |
} |
62 |
|
|
63 |
|
public FormComponentContributorContextImpl(Locale locale, IRequestCycle cycle, |
64 |
|
IFormComponent field) |
65 |
|
{ |
66 |
5 |
super(field, locale); |
67 |
|
|
68 |
5 |
_field = field; |
69 |
5 |
_form = field.getForm(); |
70 |
5 |
_formId = _form.getName(); |
71 |
|
|
72 |
5 |
_resolver = cycle.getInfrastructure().getClassResolver(); |
73 |
|
|
74 |
5 |
_pageRenderSupport = TapestryUtils.getPageRenderSupport(cycle, field); |
75 |
5 |
} |
76 |
|
|
77 |
|
public void includeClasspathScript(String path) |
78 |
|
{ |
79 |
1 |
Resource resource = new ClasspathResource(_resolver, path); |
80 |
|
|
81 |
1 |
_pageRenderSupport.addExternalScript(_form, resource); |
82 |
1 |
} |
83 |
|
|
84 |
|
public void addSubmitHandler(String submitListener) |
85 |
|
{ |
86 |
1 |
_pageRenderSupport.addInitializationScript(_form, "Tapestry.onsubmit('" + _formId + "', " |
87 |
|
+ submitListener + ");"); |
88 |
1 |
} |
89 |
|
|
90 |
|
public void addInitializationScript(IComponent target, String script) |
91 |
|
{ |
92 |
0 |
_pageRenderSupport.addInitializationScript(_form, script); |
93 |
0 |
} |
94 |
|
|
95 |
|
public void registerForFocus(int priority) |
96 |
|
{ |
97 |
0 |
_form.registerForFocus(_field, priority); |
98 |
0 |
} |
99 |
|
|
100 |
|
public JSONObject getProfile() |
101 |
|
{ |
102 |
0 |
return _form.getProfile(); |
103 |
|
} |
104 |
|
} |