1 23 24 package org.dbforms.taglib; 25 26 import org.dbforms.config.Table; 27 28 import org.dbforms.util.MessageResources; 29 import org.dbforms.util.Util; 30 31 import org.dbforms.validation.ValidatorConstants; 32 33 import java.util.Locale ; 34 35 import javax.servlet.http.HttpServletRequest ; 36 import javax.servlet.jsp.JspException ; 37 38 43 public abstract class DbBaseButtonTag extends DbBaseHandlerTag { 44 45 46 protected static final int FLAVOR_STANDARD = 0; 47 48 49 protected static final int FLAVOR_IMAGE = 1; 50 51 52 protected static final int FLAVOR_MODERN = 2; 53 54 private static int uniqueID = 0; 56 57 private String alt; 59 private String border; 61 private String caption; 63 private String disabledBehaviour; 65 66 private String disabledImageAlt; 67 68 private String disabledImageHeight; 69 70 private String disabledImageSrc; 71 72 private String disabledImageWidth; 73 74 private String followUp; 75 76 private String followUpOnError; 77 78 private String src; 80 private Table table; 81 82 private int choosenFlavor = 0; 84 90 public void setAlt(String src) { 91 this.alt = src; 92 } 93 94 99 public String getAlt() { 100 return alt; 101 } 102 103 109 public void setBorder(String border) { 110 this.border = border; 111 } 112 113 118 public String getBorder() { 119 return border; 120 } 121 122 128 public void setCaption(String caption) { 129 this.caption = caption; 130 } 131 132 137 public String getCaption() { 138 return caption; 139 } 140 141 146 public int getChoosenFlavor() { 147 return choosenFlavor; 148 } 149 150 156 public void setDisabledBehaviour(String disabledBehaviour) { 157 this.disabledBehaviour = disabledBehaviour; 158 } 159 160 165 public String getDisabledBehaviour() { 166 return disabledBehaviour; 167 } 168 169 175 public void setDisabledImageAlt(String disabledImageAlt) { 176 this.disabledImageAlt = disabledImageAlt; 177 } 178 179 185 public String getDisabledImageAlt() { 186 return disabledImageAlt; 187 } 188 189 195 public void setDisabledImageHeight(String disabledImageHeight) { 196 this.disabledImageHeight = disabledImageHeight; 197 } 198 199 204 public String getDisabledImageHeight() { 205 return disabledImageHeight; 206 } 207 208 215 public void setDisabledImageSrc(String disabledImageSrc) { 216 this.disabledImageSrc = disabledImageSrc; 217 } 218 219 224 public String getDisabledImageSrc() { 225 return disabledImageSrc; 226 } 227 228 234 public void setDisabledImageWidth(String disabledImageWidth) { 235 this.disabledImageWidth = disabledImageWidth; 236 } 237 238 243 public String getDisabledImageWidth() { 244 return disabledImageWidth; 245 } 246 247 253 public void setFlavor(String flavor) { 254 if ("image".equals(flavor)) { 255 choosenFlavor = FLAVOR_IMAGE; 256 } else if ("modern".equals(flavor)) { 257 choosenFlavor = FLAVOR_MODERN; 258 } else { 259 choosenFlavor = FLAVOR_STANDARD; 260 } 261 } 262 263 269 public void setFollowUp(String followUp) { 270 this.followUp = followUp; 271 } 272 273 278 public String getFollowUp() { 279 return followUp; 280 } 281 282 288 public void setFollowUpOnError(String followUpOnError) { 289 this.followUpOnError = followUpOnError; 290 } 291 292 297 public String getFollowUpOnError() { 298 return followUpOnError; 299 } 300 301 307 public void setParent(final javax.servlet.jsp.tagext.Tag parent) { 308 super.setParent(parent); 309 table = getParentForm().getTable(); 310 } 311 312 318 public void setSrc(String src) { 319 this.src = src; 320 } 321 322 327 public String getSrc() { 328 return src; 329 } 330 331 336 public Table getTable() { 337 return table; 338 } 339 340 350 public int doEndTag() throws javax.servlet.jsp.JspException { 351 if (choosenFlavor == FLAVOR_MODERN) { 352 try { 353 if (bodyContent != null) { 354 bodyContent.writeOut(bodyContent.getEnclosingWriter()); 355 } 356 357 pageContext.getOut().write("</button>"); 358 } catch (java.io.IOException ioe) { 359 throw new JspException ("IO Error: " + ioe.getMessage()); 360 } 361 } 362 363 return EVAL_PAGE; 364 } 365 366 369 public void doFinally() { 370 followUp = null; 371 followUpOnError = null; 372 table = null; 373 choosenFlavor = 0; 374 caption = null; 375 src = null; 376 alt = null; 377 border = null; 378 super.doFinally(); 379 } 380 381 389 public int doStartTag() throws javax.servlet.jsp.JspException { 390 if ((getParentForm().getFormValidatorName() != null) 391 && (getParentForm().getFormValidatorName().length() > 0) 392 && getParentForm().hasJavascriptValidationSet()) { 393 String onclick = (getOnClick() != null) ? getOnClick() : ""; 394 395 if (onclick.lastIndexOf(";") != (onclick.length() - 1)) { 396 onclick += ";"; } 398 399 setOnClick(onclick + JsValidation()); 400 } 401 402 return SKIP_BODY; 403 } 404 405 410 protected static synchronized int getUniqueID() { 411 uniqueID++; 412 413 return uniqueID; 414 } 415 416 422 protected String getButtonBegin() { 423 StringBuffer buf = new StringBuffer (); 424 Locale locale = MessageResources 425 .getLocale((HttpServletRequest ) pageContext.getRequest()); 426 427 String privCaption = getCaption(); 428 if ((privCaption != null) && getParentForm().hasCaptionResourceSet()) { 430 privCaption = MessageResources.getMessage(privCaption, locale); 431 } 432 433 String privAlt = getAlt(); 434 if ((privAlt != null) && getParentForm().hasCaptionResourceSet()) { 436 privAlt = MessageResources.getMessage(privAlt, locale); 437 } 438 439 switch (choosenFlavor) { 440 case FLAVOR_IMAGE: 441 buf.append("<input type=\"image\" "); 442 443 if (src != null) { 444 buf.append(" SRC=\""); 445 buf.append(src); 446 buf.append("\" "); 447 } 448 449 if (privAlt != null) { 450 buf.append(" alt=\""); 451 buf.append(privAlt); 452 buf.append("\" "); 453 } 454 455 break; 456 457 case FLAVOR_MODERN: 458 buf.append("<button type=\"submit\" "); 459 460 if (privCaption != null) { 461 buf.append(" value=\""); buf.append(privCaption); 465 buf.append("\" "); 466 } 467 468 break; 469 470 default: buf.append("<input type=\"submit\" "); 472 473 if (privCaption != null) { 474 buf.append(" value=\""); buf.append(privCaption); 477 buf.append("\" "); 478 } 479 } 480 481 buf.append(prepareStyles()); 482 buf.append(prepareEventHandlers()); 483 484 return buf.toString(); 485 } 486 487 493 protected String getButtonEnd() { 494 switch (choosenFlavor) { 495 case FLAVOR_IMAGE: 496 return "\"/>"; 497 498 case FLAVOR_MODERN: 499 return "\">"; 500 501 default: 503 return "\"/>"; 504 } 505 } 506 507 520 protected String getDataTag(String primaryTagName, String dataKey, 521 String dataValue) { 522 String s = ""; 523 524 if (!Util.isNull(dataValue)) { 525 StringBuffer tagBuf = new StringBuffer (); 526 tagBuf.append("<input type=\"hidden\" name=\"data"); 527 tagBuf.append(primaryTagName); 528 tagBuf.append("_"); 529 tagBuf.append(dataKey); 530 tagBuf.append("\" value =\""); 531 tagBuf.append(dataValue); 532 tagBuf.append("\"/>"); 533 s = tagBuf.toString(); 534 } 535 536 return s; 537 } 538 539 541 546 protected String getDisabledImage() { 547 StringBuffer imgBuf = new StringBuffer (); 548 549 imgBuf.append("<img SRC=\""); 551 imgBuf.append(getDisabledImageSrc()); 552 imgBuf.append("\""); 553 554 imgBuf.append(" alt=\""); 556 imgBuf.append(getDisabledImageAlt()); 557 imgBuf.append("\""); 558 559 imgBuf.append(prepareStyles()); 561 562 if (!Util.isNull(getDisabledImageWidth())) { 566 imgBuf.append(" width=\""); 567 imgBuf.append(getDisabledImageWidth()); 568 imgBuf.append("\""); 569 } 570 571 if (!Util.isNull(getDisabledImageHeight())) { 572 imgBuf.append(" height=\""); 573 imgBuf.append(getDisabledImageHeight()); 574 imgBuf.append("\""); 575 } 576 577 imgBuf.append(" />"); 578 579 return imgBuf.toString(); 580 } 581 582 588 protected String JsValidation() { 589 return ValidatorConstants.JS_CANCEL_VALIDATION + "=false;"; 590 } 591 592 597 protected String prepareStyles() { 598 StringBuffer styles = new StringBuffer (super.prepareStyles()); 599 600 if (border != null) { 601 styles.append(" border=\""); 602 styles.append(border); 603 styles.append("\""); 604 } 605 606 return styles.toString(); 607 } 608 } 609 | Popular Tags |