1 package fr.improve.struts.taglib.layout.field; 2 3 import javax.servlet.jsp.JspException ; 4 5 import org.apache.struts.taglib.html.BaseHandlerTag; 6 import org.apache.struts.taglib.html.Constants; 7 import org.apache.struts.util.ResponseUtils; 8 9 import fr.improve.struts.taglib.layout.el.Expression; 10 import fr.improve.struts.taglib.layout.util.LayoutUtils; 11 import fr.improve.struts.taglib.layout.util.TagUtils; 12 20 public abstract class AbstractFieldTag extends AbstractLayoutFieldTag { 21 24 protected BaseHandlerTag fieldTag; 25 26 29 protected String value; 30 protected String accept; 31 protected String cols; 32 protected String maxlength; 33 protected String rows; 34 protected String size; 35 protected String accesskey; 36 protected String onblur; 37 protected String onclick; 38 protected String ondblclick; 39 protected String onfocus; 40 protected String onkeydown; 41 protected String onkeyup; 42 protected String onkeypress; 43 protected String onmouseup; 44 protected String onmouseout; 45 protected String onmousemove; 46 protected String onmouseover; 47 protected String onmousedown; 48 49 protected String tabIndex; 50 protected String onchange; 51 protected String onselect; 52 protected boolean filter = true; 53 54 57 protected String jspValue; 58 59 public AbstractFieldTag() { 60 super(); 61 name = Constants.BEAN_KEY; 62 } 63 64 65 protected void doAfterValue() throws JspException { 66 } 68 74 protected abstract boolean doBeforeValue() throws JspException ; 75 public int doEndEditField() throws JspException { 76 return EVAL_PAGE; 77 } 78 public int doEndInspectField() throws JspException { 79 return EVAL_PAGE; 80 } 81 public int doStartEditField() throws JspException { 82 if (!doBeforeValue()) return SKIP_BODY; 84 85 if (fieldTag == null) throw new JspException (getClass().getName() + " should really set the fieldTag value in doBeforeValue() !"); 87 88 copyProperties(fieldTag); 90 91 boolean check = isRequired(); 93 if (check) { 94 StringBuffer lc_buffer = new StringBuffer ("checkValue(this, '"); 95 lc_buffer.append(property).append("','TEXT',").append(check).append(");"); 96 if (fieldTag.getOnchange()!=null) { 97 lc_buffer.append(fieldTag.getOnchange()); 98 } 99 fieldTag.setOnchange(lc_buffer.toString()); 100 } 101 102 fieldTag.doStartTag(); 103 fieldTag.doEndTag(); 104 105 doAfterValue(); 106 107 return EVAL_BODY_INCLUDE; 108 } 109 protected void copyProperties (BaseHandlerTag in_dest) throws JspException { 110 113 fieldTag.setAccesskey(getAccesskey()); 115 fieldTag.setDisabled(isDisabledAsBoolean()); 119 fieldTag.setId(getId()); 120 fieldTag.setOnblur(getOnblur()); 123 fieldTag.setOnchange(Expression.evaluate(getOnchange(), pageContext)); 124 fieldTag.setOnclick(getOnclick()); 125 fieldTag.setOndblclick(getOndblclick()); 126 fieldTag.setOnfocus(getOnfocus()); 127 fieldTag.setOnkeydown(getOnkeydown()); 128 fieldTag.setOnkeypress(getOnkeypress()); 129 fieldTag.setOnkeyup(getOnkeyup()); 130 fieldTag.setOnmousedown(getOnmousedown()); 131 fieldTag.setOnmousemove(getOnmousemove()); 132 fieldTag.setOnmouseout(getOnmouseout()); 133 fieldTag.setOnmouseover(getOnmouseover()); 134 fieldTag.setOnmouseup(getOnmouseup()); 135 fieldTag.setOnselect(getOnselect()); 136 fieldTag.setPageContext(getPageContext()); 137 fieldTag.setParent(getParent()); 138 fieldTag.setReadonly(isReadonly()); 139 fieldTag.setStyle(getStyle()); 140 fieldTag.setStyleClass(getStyleClass()); 141 fieldTag.setStyleId(getStyleId()); 142 fieldTag.setTabindex(getTabindex()); 143 fieldTag.setTitle(LayoutUtils.getLabel(getPageContext(), getBundle(), Expression.evaluate(getTooltip(), pageContext), null, false)); 144 146 } 147 public int doStartInspectField() throws JspException { 148 if (!doBeforeValue()) return SKIP_BODY; 150 151 Object lc_value = getFieldValue(); 152 if (lc_value!=null) { 153 StringBuffer buffer = new StringBuffer (); 154 buffer.append("<span class=\""); 155 buffer.append(styleClass); 156 buffer.append("\">"); 157 if (filter) { 158 buffer.append(ResponseUtils.filter(lc_value.toString())); 159 } else { 160 buffer.append(lc_value.toString()); 161 } 162 buffer.append("</span>"); 163 TagUtils.write(pageContext, buffer.toString()); 164 } 165 166 doAfterValue(); 167 168 return EVAL_BODY_INCLUDE; 169 } 170 public String getAccept() { 171 return accept; 172 } 173 public String getCols() { 174 return cols; 175 } 176 protected Object getFieldValue() throws JspException { 177 if (value!=null) return value; 178 return LayoutUtils.getBeanFromPageContext(pageContext, name, property); 179 } 180 public String getMaxlength() { 181 return maxlength; 182 } 183 public String getRows() { 184 return rows; 185 } 186 public String getSize() { 187 return cols; 188 } 189 public BaseHandlerTag getFieldTag() { 190 return fieldTag; 191 } 192 public String getValue() { 193 try { 194 Object lc_value = getFieldValue(); 195 if (lc_value != null) return lc_value.toString(); 196 } catch (JspException e) { 197 } 199 return ""; 200 } 201 protected void reset() { 202 super.reset(); 203 if (fieldTag!=null) { 204 fieldTag.release(); 205 fieldTag = null; 206 } 207 value = jspValue; 208 jspValue = null; 209 } 210 public void release() { 211 super.release(); 212 213 name = Constants.BEAN_KEY; 214 accept = null; 215 accesskey = null; 216 cols = null; 217 filter = true; 218 maxlength = null; 219 onblur = null; 220 onchange = null; 221 onclick = null; 222 ondblclick = null; 223 onfocus = null; 224 onkeydown = null; 225 onkeyup = null; 226 onmousedown = null; 227 onmousemove = null; 228 onmouseout = null; 229 onmouseover = null; 230 onmouseup = null; 231 onselect = null; 232 rows = null; 233 size = null; 234 tabIndex = null; 235 value = null; 236 } 237 public void setAccept(String accept) { 238 this.accept = accept; 239 } 240 245 public void setCols(String newCols) { 246 cols = newCols; 247 } 248 public void setMaxlength(String maxlength) { 249 this.maxlength = maxlength; 250 } 251 256 public void setRows(String newRows) { 257 rows = newRows; 258 } 259 264 public void setSize(String newSize) { 265 cols = newSize; 266 } 267 public void setValue(String value) { 268 this.value = value; 269 } 270 274 public String getAccesskey() { 275 return accesskey; 276 } 277 278 282 public void setAccesskey(String accesskey) { 283 this.accesskey = accesskey; 284 } 285 286 290 public String getOnblur() { 291 return onblur; 292 } 293 294 298 public void setOnblur(String onblur) { 299 this.onblur = onblur; 300 } 301 302 306 public String getOnclick() { 307 return onclick; 308 } 309 310 314 public void setOnclick(String onclick) { 315 this.onclick = onclick; 316 } 317 318 322 public String getOndblclick() { 323 return ondblclick; 324 } 325 326 330 public void setOndblclick(String ondblclick) { 331 this.ondblclick = ondblclick; 332 } 333 334 338 public String getOnkeyup() { 339 return onkeyup; 340 } 341 342 346 public void setOnkeyup(String onkeyup) { 347 this.onkeyup = onkeyup; 348 } 349 350 354 public String getOnkeydown() { 355 return onkeydown; 356 } 357 358 362 public void setOnkeydown(String onkeydown) { 363 this.onkeydown = onkeydown; 364 } 365 366 370 public String getOnfocus() { 371 return onfocus; 372 } 373 374 378 public void setOnfocus(String onfocus) { 379 this.onfocus = onfocus; 380 } 381 382 386 public String getOnkeypress() { 387 return onkeypress; 388 } 389 390 394 public void setOnkeypress(String onkeypress) { 395 this.onkeypress = onkeypress; 396 } 397 398 402 public String getOnmouseout() { 403 return onmouseout; 404 } 405 406 410 public void setOnmouseout(String onmouseout) { 411 this.onmouseout = onmouseout; 412 } 413 414 418 public String getOnmouseup() { 419 return onmouseup; 420 } 421 422 426 public void setOnmouseup(String onmouseup) { 427 this.onmouseup = onmouseup; 428 } 429 430 434 public String getOnmousemove() { 435 return onmousemove; 436 } 437 438 442 public void setOnmousemove(String onmousemove) { 443 this.onmousemove = onmousemove; 444 } 445 446 450 public String getOnmouseover() { 451 return onmouseover; 452 } 453 454 458 public void setOnmouseover(String onmouseover) { 459 this.onmouseover = onmouseover; 460 } 461 462 466 public String getOnmousedown() { 467 return onmousedown; 468 } 469 470 474 public void setOnmousedown(String onmousedown) { 475 this.onmousedown = onmousedown; 476 } 477 478 482 public String getTabindex() { 483 return tabIndex; 484 } 485 486 490 public void setTabindex(String tabIndex) { 491 this.tabIndex = tabIndex; 492 } 493 494 498 public String getOnselect() { 499 return onselect; 500 } 501 502 506 public void setOnselect(String onselect) { 507 this.onselect = onselect; 508 } 509 510 514 public String getOnchange() { 515 return onchange; 516 } 517 518 522 public void setOnchange(String onchange) { 523 this.onchange = onchange; 524 } 525 526 530 public void setFilter(boolean filter) { 531 this.filter = filter; 532 } 533 534 537 protected void initDynamicValues() { 538 super.initDynamicValues(); 539 540 jspValue = value; 542 value = Expression.evaluate(jspValue, pageContext); 543 } 544 } 545 | Popular Tags |