View Javadoc

1   package net.sf.tacos.components;
2   
3   import java.util.HashMap;
4   import java.util.Map;
5   
6   import org.apache.tapestry.BaseComponent;
7   import org.apache.tapestry.IMarkupWriter;
8   import org.apache.tapestry.IRequestCycle;
9   import org.apache.tapestry.IScript;
10  import org.apache.tapestry.TapestryUtils;
11  import org.apache.tapestry.form.IFormComponent;
12  
13  /**
14   * Provides a hint for a form field to guide the user on how to fill it.
15   * The box with the helper text appears when the field is focused and disappears when the focus is lost.
16   * 
17   * @author Igor Drobiazko
18   */
19  public abstract class FieldHint extends BaseComponent {
20  	/**
21       * {@inheritDoc}
22       */
23  	protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle) {
24  		writer.begin("span");
25          renderIdAttribute(writer, cycle);
26          writer.appendAttribute("class", "hint");
27          renderBody(writer, cycle);
28          super.renderComponent(writer, cycle);
29          writer.end();
30          
31          if (!cycle.isRewinding()) {
32              Map parms = new HashMap();
33              parms.put("component", this);
34              parms.put("startEvent", getStartEvent());
35              parms.put("endEvent", getEndEvent());
36  
37              getScript().execute(this, cycle, TapestryUtils.getPageRenderSupport(cycle, this), parms);
38              }
39  	}
40  	
41      /** Injected {@link IScript}. */
42      public abstract IScript getScript();
43      
44      /** Field parameter. */
45      public abstract IFormComponent getField();
46      
47      /** The js event of the form component that should make the hint visible. */
48      public abstract String getStartEvent();
49      
50      /** The js event of the form component that should make the hint hidden. */
51      public abstract String getEndEvent();    
52  }