1 16 package org.apache.taglibs.input; 17 18 import java.util.Map ; 19 20 import javax.servlet.ServletRequest ; 21 import javax.servlet.jsp.JspException ; 22 import javax.servlet.jsp.JspTagException ; 23 import javax.servlet.jsp.JspWriter ; 24 import javax.servlet.jsp.tagext.BodyTagSupport ; 25 26 36 37 public class TextArea extends BodyTagSupport { 38 39 private String name; 41 private String dVal; 43 private Map attributes; 45 private String attributesText; 47 private String beanId; 49 private String cols, rows; 50 51 public void release() { 52 super.release(); 53 name = null; 54 dVal = null; 55 attributes = null; 56 attributesText = null; 57 beanId = null; 58 cols = null; 59 rows = null; 60 } 61 62 public int doEndTag() throws JspException { 63 try { 64 if (name == null || name.equals("")) 66 throw new JspTagException ("invalid null or empty 'name'"); 67 68 String beanId = this.beanId; 70 71 if (beanId == null) { 73 beanId = Util.defaultFormBeanId(this); 74 } else if (beanId.length() == 0) { 75 beanId = null; 77 } 78 79 ServletRequest req = pageContext.getRequest(); 81 JspWriter out = pageContext.getOut(); 82 83 out.print("<textarea name=\"" + Util.quote(name) + "\" "); 85 86 Util.printAttributes(out, attributes); 88 if (attributesText != null) { 89 out.print(attributesText + " "); 90 } 91 92 if (cols != null) { 93 out.print("cols=\"" + Util.quote(cols) + "\" "); 94 } 95 if (rows != null) { 96 out.print("rows=\"" + Util.quote(rows) + "\" "); 97 } 98 99 out.print(">"); 101 102 String defaultValue = dVal; 103 if (getBodyContent() != null 104 && getBodyContent().getString() != null) { 105 defaultValue = getBodyContent().getString(); 106 } 107 108 112 String beanValue = (beanId != null ? Util.beanPropertyValue( 113 pageContext.findAttribute(beanId), name) : null); 114 if (beanValue != null) { 115 out.print(Util.quote(beanValue)); 116 } else if (req.getParameter(name) != null) { 117 out.print(Util.quote(req.getParameter(name))); 118 } else { 119 if (defaultValue != null) 120 out.print(Util.quote(defaultValue)); 121 } 122 123 out.print("</textarea>"); 125 126 } catch (Exception ex) { 127 throw new JspTagException (ex.getMessage()); 128 } 129 return EVAL_PAGE; 130 } 131 132 public void setName(String x) { 133 name = x; 134 } 135 136 public void setAttributes(Map x) { 137 attributes = x; 138 } 139 140 public void setAttributesText(String x) { 141 attributesText = x; 142 } 143 144 public void setBean(String x) { 145 beanId = x; 146 } 147 148 public void setDefault(String x) { 149 dVal = x; 150 } 151 152 157 public String getName() { 158 return name; 159 } 160 161 166 public String getDefault() { 167 return dVal; 168 } 169 170 175 public String getBean() { 176 return beanId; 177 } 178 179 184 public String getAttributesText() { 185 return attributesText; 186 } 187 188 193 public Map getAttributes() { 194 return attributes; 195 } 196 197 public void setCols(String cols) { 198 this.cols = cols; 199 } 200 201 public void setRows(String rows) { 202 this.rows = rows; 203 } 204 } | Popular Tags |