1 24 package org.riotfamily.forms.element; 25 26 import java.io.PrintWriter ; 27 28 import org.riotfamily.common.markup.Html; 29 import org.riotfamily.common.markup.TagWriter; 30 import org.riotfamily.forms.DHTMLElement; 31 import org.riotfamily.forms.resource.FormResource; 32 import org.riotfamily.forms.resource.ResourceElement; 33 import org.riotfamily.forms.resource.Resources; 34 import org.riotfamily.forms.resource.ScriptResource; 35 36 37 40 public class Textarea extends AbstractTextElement implements ResourceElement, 41 DHTMLElement { 42 43 private static FormResource RESOURCE = new ScriptResource( 44 "riot-js/textarea.js", "RiotTextArea", Resources.RIOT_UTIL); 45 46 private Integer rows = null; 47 48 private Integer cols = null; 49 50 public void setCols(Integer cols) { 51 this.cols = cols; 52 } 53 54 public void setRows(Integer rows) { 55 this.rows = rows; 56 } 57 58 public void renderInternal(PrintWriter writer) { 59 TagWriter tag = new TagWriter(writer); 60 tag.start(Html.TEXTAREA) 61 .attribute(Html.COMMON_CLASS, getStyleClass()) 62 .attribute(Html.COMMON_ID, getId()) 63 .attribute(Html.INPUT_NAME, getParamName()); 64 65 if (rows != null) { 66 tag.attribute(Html.TEXTAREA_ROWS, rows.intValue()); 67 } 68 if (cols != null) { 69 tag.attribute(Html.TEXTAREA_COLS, cols.intValue()); 70 } 71 72 tag.body(getText()).end(); 73 } 74 75 public FormResource getResource() { 76 return RESOURCE; 77 } 78 79 public String getInitScript() { 80 if (getMaxLength() != null || rows == null) { 81 StringBuffer sb = new StringBuffer (); 82 sb.append("new RiotTextArea('").append(getId()).append("')"); 83 if (getMaxLength() != null) { 84 sb.append(".setMaxLength(").append(getMaxLength()).append(')'); 85 } 86 if (rows == null) { 87 sb.append(".autoResize()"); 88 } 89 sb.append(';'); 90 return sb.toString(); 91 } 92 return null; 93 } 94 95 } | Popular Tags |