1 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.IForm; 23 import org.apache.tapestry.IRequestCycle; 24 import org.apache.tapestry.PageRenderSupport; 25 import org.apache.tapestry.TapestryUtils; 26 27 33 public class FormComponentContributorContextImpl extends ValidationMessagesImpl implements 34 FormComponentContributorContext 35 { 36 private final ClassResolver _resolver; 37 38 private final String _formDOM; 39 40 private final String _fieldDOM; 41 42 private final PageRenderSupport _pageRenderSupport; 43 44 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 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 getFieldDOM() 74 { 75 return _fieldDOM; 76 } 77 78 public void includeClasspathScript(String path) 79 { 80 Resource resource = new ClasspathResource(_resolver, path); 81 82 _pageRenderSupport.addExternalScript(resource); 83 } 84 85 public void addSubmitListener(String submitListener) 86 { 87 _pageRenderSupport.addInitializationScript(_formDOM + ".events.addSubmitListener(" 88 + submitListener + ");"); 89 } 90 } 91 | Popular Tags |