$form

 

The form demonstrates a custom RichTextArea control using the TinyMCE JavaScript library. The control overrides the Field method getHtmlImports() to include its JavaScript imports automatically:
protected static final String HTML_IMPORTS =
    "<script type=\"text/javascript\" src=\"{0}/tiny_mce/tiny_mce.js\"></script>\n";

public String getHtmlImports() {
    String[] args = { getContext().getRequest().getContextPath() };
    return MessageFormat.format(HTML_IMPORTS, args);
} 
The control's HTML is rendered using the toString() method. First is uses the parent TextArea class to render itself and then appends the TinyMCE JavaScript initialization code.
public String toString() {
    HtmlStringBuffer buffer = new HtmlStringBuffer();
    buffer.append(super.toString());

    buffer.elementStart("script");
    buffer.appendAttribute("type", "text/javascript");
    buffer.closeTag();
    buffer.append("\ntinyMCE.init({\n");
    buffer.append("   theme : \"");
    buffer.append(getTheme());
    buffer.append("\",\n");
    buffer.append("   mode : \"exact\",\n");
    buffer.append("   elements : \"");
    buffer.append(getId());
    buffer.append("\"\n");
    buffer.append("});\n");
    buffer.elementEnd("script");

    return buffer.toString();
}