KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > form > FormComponentContributorContextImpl


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 java.util.Locale JavaDoc;
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.IForm;
23 import org.apache.tapestry.IRequestCycle;
24 import org.apache.tapestry.PageRenderSupport;
25 import org.apache.tapestry.TapestryUtils;
26
27 /**
28  * Implementation of {@link org.apache.tapestry.form.FormComponentContributorContext}.
29  *
30  * @author Howard Lewis Ship
31  * @since 4.0
32  */

33 public class FormComponentContributorContextImpl extends ValidationMessagesImpl implements
34         FormComponentContributorContext
35 {
36     private final ClassResolver _resolver;
37
38     private final String JavaDoc _formDOM;
39
40     private final String JavaDoc _fieldDOM;
41
42     private final PageRenderSupport _pageRenderSupport;
43
44     /**
45      * Used for testing.
46      */

47
48     FormComponentContributorContextImpl()
49     {
50         super(Locale.ENGLISH);
51
52         _resolver = null;
53         _formDOM = null;
54         _fieldDOM = null;
55         _pageRenderSupport = null;
56     }
57
58     public FormComponentContributorContextImpl(Locale JavaDoc locale, IRequestCycle cycle,
59             IFormComponent component)
60     {
61         super(locale);
62
63         IForm form = component.getForm();
64
65         _resolver = cycle.getInfrastructure().getClassResolver();
66
67         _formDOM = "document." + form.getName();
68         _fieldDOM = _formDOM + "." + component.getName();
69
70         _pageRenderSupport = TapestryUtils.getPageRenderSupport(cycle, component);
71     }
72
73     public String JavaDoc getFieldDOM()
74     {
75         return _fieldDOM;
76     }
77
78     public void includeClasspathScript(String JavaDoc path)
79     {
80         Resource resource = new ClasspathResource(_resolver, path);
81
82         _pageRenderSupport.addExternalScript(resource);
83     }
84
85     public void addSubmitListener(String JavaDoc submitListener)
86     {
87         _pageRenderSupport.addInitializationScript(_formDOM + ".events.addSubmitListener("
88                 + submitListener + ");");
89     }
90 }
91
Popular Tags