|
|||||||||||||||||||
30 day Evaluation License registered to hlship@comcast.net Your 30 day evaluation period has expired. Please visit http://www.cenqua.com to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
AbstractFormComponentContributor.java | 100% | 62.5% | 57.1% | 64.7% |
|
1 | // Copyright 2005 The Apache Software Foundation | |
2 | // | |
3 | // Licensed under the Apache License, Version 2.0 (the "License"); | |
4 | // you may not use this file except in compliance with the License. | |
5 | // You may obtain a copy of the License at | |
6 | // | |
7 | // http://www.apache.org/licenses/LICENSE-2.0 | |
8 | // | |
9 | // Unless required by applicable law or agreed to in writing, software | |
10 | // distributed under the License is distributed on an "AS IS" BASIS, | |
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
12 | // See the License for the specific language governing permissions and | |
13 | // limitations under the License. | |
14 | ||
15 | package org.apache.tapestry.form; | |
16 | ||
17 | import org.apache.hivemind.Resource; | |
18 | import org.apache.hivemind.util.ClasspathResource; | |
19 | import org.apache.hivemind.util.PropertyUtils; | |
20 | import org.apache.tapestry.IForm; | |
21 | import org.apache.tapestry.IMarkupWriter; | |
22 | import org.apache.tapestry.IRequestCycle; | |
23 | import org.apache.tapestry.TapestryUtils; | |
24 | ||
25 | /** | |
26 | * Abstract {@link FormComponentContributor} implementation that adds an optional static | |
27 | * javscript method reference to the page. | |
28 | * | |
29 | * @author Paul Ferraro | |
30 | * @since 4.0 | |
31 | */ | |
32 | public abstract class AbstractFormComponentContributor implements FormComponentContributor | |
33 | { | |
34 | private String _script = defaultScript(); | |
35 | ||
36 | 30 | public AbstractFormComponentContributor() |
37 | { | |
38 | } | |
39 | ||
40 | // Needed until HIVEMIND-134 fix is available | |
41 | 0 | public AbstractFormComponentContributor(String initializer) |
42 | { | |
43 | 0 | PropertyUtils.configureProperties(this, initializer); |
44 | } | |
45 | ||
46 | /** | |
47 | * Defines the default JavaScript file used by this contributor. Overriden by most subclasses | |
48 | * that use JavaScript. | |
49 | */ | |
50 | 19 | protected String defaultScript() |
51 | { | |
52 | 19 | return null; |
53 | } | |
54 | ||
55 | 0 | public String getScript() |
56 | { | |
57 | 0 | return _script; |
58 | } | |
59 | ||
60 | 0 | public void setScript(String script) |
61 | { | |
62 | 0 | _script = script; |
63 | } | |
64 | ||
65 | /** | |
66 | * @see org.apache.tapestry.form.FormComponentContributor#renderContribution(org.apache.tapestry.IMarkupWriter, org.apache.tapestry.IRequestCycle, FormComponentContributorContext, org.apache.tapestry.form.IFormComponent) | |
67 | */ | |
68 | 7 | public void renderContribution(IMarkupWriter writer, IRequestCycle cycle, FormComponentContributorContext context, IFormComponent field) |
69 | { | |
70 | 7 | if (_script != null) |
71 | { | |
72 | // TODO: cycle.getInfrastructure().getClassResolver() | |
73 | ||
74 | 3 | Resource script = new ClasspathResource(cycle.getEngine().getClassResolver(), _script); |
75 | ||
76 | 3 | TapestryUtils.getPageRenderSupport(cycle, field).addExternalScript(script); |
77 | } | |
78 | } | |
79 | ||
80 | /** | |
81 | * Helper method that adds the specified submit handler to to the specified form. | |
82 | */ | |
83 | 6 | protected void addSubmitHandler(IForm form, String handler) |
84 | { | |
85 | 6 | form.addEventHandler(FormEventType.SUBMIT, handler); |
86 | } | |
87 | } |
|