1 18 package org.apache.beehive.netui.tags.html; 19 20 import org.apache.beehive.netui.tags.ByRef; 21 import org.apache.beehive.netui.tags.HtmlUtils; 22 import org.apache.beehive.netui.tags.rendering.AbstractHtmlState; 23 import org.apache.beehive.netui.tags.rendering.TagRenderingBase; 24 import org.apache.beehive.netui.tags.rendering.TextAreaTag; 25 import org.apache.beehive.netui.tags.rendering.WriteRenderAppender; 26 27 import javax.servlet.ServletRequest ; 28 import javax.servlet.jsp.JspException ; 29 import java.util.ArrayList ; 30 31 45 public class TextArea extends HtmlDefaultableDataSourceTag 46 implements IFormattable 47 { 48 private TextAreaTag.State _state = new TextAreaTag.State(); 49 50 private ArrayList _formatters = null; 51 private boolean _formatErrors = false; 52 53 56 public String getTagName() 57 { 58 return "TextArea"; 59 } 60 61 66 protected AbstractHtmlState getState() 67 { 68 return _state; 69 } 70 71 78 public void setAttribute(String name, String value, String facet) 79 throws JspException ![JavaDoc](../../../../../../../cmn/javadoc.gif) 80 { 81 if (name != null) { 82 if (name.equals(DISABLED)) { 83 _state.disabled = new Boolean (value).booleanValue(); 84 return; 85 } 86 else if (name.equals(READONLY)) { 87 _state.readonly = new Boolean (value).booleanValue(); 88 return; 89 } 90 else if (name.equals(COLS)) { 91 _state.cols = Integer.parseInt(value); 92 return; 93 } 94 else if (name.equals(ROWS)) { 95 _state.rows = Integer.parseInt(value); 96 return; 97 } 98 } 99 100 super.setAttribute(name, value, facet); 101 } 102 103 112 public void setCols(int cols) 113 { 114 _state.cols = cols; 115 } 116 117 126 public void setReadonly(boolean readonly) 127 { 128 _state.readonly = readonly; 129 } 130 131 140 public void setRows(int rows) 141 { 142 _state.rows = rows; 143 } 144 145 149 public int doStartTag() throws JspException ![JavaDoc](../../../../../../../cmn/javadoc.gif) 150 { 151 return EVAL_BODY_BUFFERED; 152 } 153 154 158 public int doEndTag() throws JspException ![JavaDoc](../../../../../../../cmn/javadoc.gif) 159 { 160 ServletRequest req = pageContext.getRequest(); 161 Object textObject = null; 162 163 Object val = evaluateDataSource(); 165 textObject = (val != null) ? val : ""; 166 assert(textObject != null); 167 168 ByRef ref = new ByRef(); 170 nameHtmlControl(_state, ref); 171 172 _state.disabled = isDisabled(); 173 174 if (hasErrors()) 176 return reportAndExit(EVAL_PAGE); 177 178 if (_formatErrors) { 180 if (bodyContent != null) { 181 String value = bodyContent.getString().trim(); 182 bodyContent.clearBody(); 183 write(value); 184 } 185 } 186 187 WriteRenderAppender writer = new WriteRenderAppender(pageContext); 189 TagRenderingBase br = TagRenderingBase.Factory.getRendering(TagRenderingBase.TEXT_AREA_TAG, req); 190 br.doStartTag(writer, _state); 191 192 if ((textObject == null) || (textObject.toString().length() == 0)) { 194 textObject = _defaultValue; 195 } 196 197 String text = formatText(textObject); 198 if (text != null) 199 HtmlUtils.filter(text, writer); 200 201 br.doEndTag(writer); 203 204 if (hasErrors()) 206 return reportAndExit(EVAL_PAGE); 207 208 if (!ref.isNull()) 210 write((String ) ref.getRef()); 211 212 localRelease(); 213 return EVAL_PAGE; 214 } 215 216 219 protected void localRelease() 220 { 221 super.localRelease(); 222 223 _state.clear(); 224 _formatters = null; 225 _formatErrors = false; 226 } 227 228 232 public void addFormatter(FormatTag.Formatter formatter) 233 { 234 if (_formatters == null) 235 _formatters = new ArrayList (); 236 237 _formatters.add(formatter); 238 } 239 240 244 public void formatterHasError() 245 { 246 _formatErrors = true; 247 } 248 249 251 private String formatText(Object text) 252 throws JspException ![JavaDoc](../../../../../../../cmn/javadoc.gif) 253 { 254 if (text == null) 255 return null; 256 if (_formatters == null) 257 return text.toString(); 258 259 for (int i = 0; i < _formatters.size(); i++) { 260 FormatTag.Formatter currentFormatter = (FormatTag.Formatter) _formatters.get(i); 261 try { 262 text = currentFormatter.format(text); 263 } 264 catch (JspException e) { 265 registerTagError(e.getMessage(), null); 266 } 267 } 268 return text.toString(); 269 } 270 271 277 278 296 public void setAccessKey(char accessKey) 297 { 298 _state.registerAttribute(AbstractHtmlState.ATTR_GENERAL, "accesskey", Character.toString(accessKey)); 299 } 300 301 312 public void setTabindex(int tabindex) 313 { 314 _state.registerAttribute(AbstractHtmlState.ATTR_GENERAL, TABINDEX, Integer.toString(tabindex)); 315 } 316 } 317 | Popular Tags |