1 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 32 public abstract class AbstractFormComponentContributor implements FormComponentContributor 33 { 34 private String _script = defaultScript(); 35 36 public AbstractFormComponentContributor() 37 { 38 } 39 40 public AbstractFormComponentContributor(String initializer) 42 { 43 PropertyUtils.configureProperties(this, initializer); 44 } 45 46 50 protected String defaultScript() 51 { 52 return null; 53 } 54 55 public String getScript() 56 { 57 return _script; 58 } 59 60 public void setScript(String script) 61 { 62 _script = script; 63 } 64 65 68 public void renderContribution(IMarkupWriter writer, IRequestCycle cycle, FormComponentContributorContext context, IFormComponent field) 69 { 70 if (_script != null) 71 { 72 74 Resource script = new ClasspathResource(cycle.getEngine().getClassResolver(), _script); 75 76 TapestryUtils.getPageRenderSupport(cycle, field).addExternalScript(script); 77 } 78 } 79 80 83 protected void addSubmitHandler(IForm form, String handler) 84 { 85 form.addEventHandler(FormEventType.SUBMIT, handler); 86 } 87 } 88 | Popular Tags |