001 package net.sf.tacos.components; 002 003 import java.util.HashMap; 004 import java.util.Map; 005 006 import org.apache.tapestry.BaseComponent; 007 import org.apache.tapestry.IMarkupWriter; 008 import org.apache.tapestry.IRequestCycle; 009 import org.apache.tapestry.IScript; 010 import org.apache.tapestry.TapestryUtils; 011 import org.apache.tapestry.form.IFormComponent; 012 013 /** 014 * Provides a hint for a form field to guide the user on how to fill it. 015 * The box with the helper text appears when the field is focused and disappears when the focus is lost. 016 * 017 * @author Igor Drobiazko 018 */ 019 public abstract class FieldHint extends BaseComponent { 020 /** 021 * {@inheritDoc} 022 */ 023 protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle) { 024 writer.begin("span"); 025 renderIdAttribute(writer, cycle); 026 writer.appendAttribute("class", "hint"); 027 renderBody(writer, cycle); 028 super.renderComponent(writer, cycle); 029 writer.end(); 030 031 if (!cycle.isRewinding()) { 032 Map parms = new HashMap(); 033 parms.put("component", this); 034 parms.put("startEvent", getStartEvent()); 035 parms.put("endEvent", getEndEvent()); 036 037 getScript().execute(this, cycle, TapestryUtils.getPageRenderSupport(cycle, this), parms); 038 } 039 } 040 041 /** Injected {@link IScript}. */ 042 public abstract IScript getScript(); 043 044 /** Field parameter. */ 045 public abstract IFormComponent getField(); 046 047 /** The js event of the form component that should make the hint visible. */ 048 public abstract String getStartEvent(); 049 050 /** The js event of the form component that should make the hint hidden. */ 051 public abstract String getEndEvent(); 052 }