1 package fr.improve.struts.taglib.layout.field; 2 3 import javax.servlet.jsp.JspException ; 4 5 import org.apache.struts.taglib.html.Constants; 6 7 import fr.improve.struts.taglib.layout.util.LayoutUtils; 8 import fr.improve.struts.taglib.layout.util.TagUtils; 9 10 14 public abstract class AbstractSelectTag extends AbstractLayoutFieldTag implements ChoiceTag { 15 protected String accesskey; 16 protected String maxlength; 17 protected String onblur; 18 protected String onclick; 19 protected String ondblclick; 20 protected String onfocus; 21 protected String onkeydown; 22 protected String onkeyup; 23 protected String onkeypress; 24 protected String onmouseup; 25 protected String onmouseout; 26 protected String onmousemove; 27 protected String onmouseover; 28 protected String onmousedown; 29 protected String onchange; 30 31 34 protected int cols = 0; 35 protected int index = 0; 36 37 41 public static final String OTHER_KEY = "struts.layout.other"; 42 protected String otherKey = "struts.layout.other"; 43 protected boolean need_other = false; 44 protected String otherProperty; 45 protected String otherValue; 46 public AbstractSelectTag() { 47 name = Constants.BEAN_KEY; 48 } 49 54 public abstract boolean add1Choice(StringBuffer sb, String value) throws JspException ; 55 56 59 public final void addChoice(StringBuffer out_buffer, Choice in_choice) throws JspException { 60 addChoice(out_buffer, in_choice.getChoiceValue(), in_choice.getChoiceLabel(), in_choice.getChoiceTooltip()); 61 } 62 63 public final void addChoice(StringBuffer buffer, String value, String label) throws JspException { 64 addChoice(buffer, value, label, null); 65 } 66 67 protected final void addChoice(StringBuffer buffer, String value, String label, String tooltip) throws JspException { 68 StringBuffer valueBuffer = new StringBuffer (); 69 boolean selected = add1Choice(valueBuffer, value); 70 short displayMode = getFieldDisplayMode(); 71 if (!selected && ((displayMode == MODE_INSPECT) || (displayMode == MODE_INSPECT_ONLY) || (displayMode == MODE_INSPECT_PRESENT))) return; 72 73 if (cols != 0) { 74 if (index % cols == 0 && index != 0) 75 buffer.append("</tr>\n<tr>"); 76 buffer.append("<td>"); 77 } 78 79 index++; 80 buffer.append(valueBuffer.toString()); 81 if (selected || getFieldDisplayMode() == MODE_EDIT) { 82 if (styleClass != null) { 83 buffer.append("<span class=\""); 84 buffer.append(styleClass); 85 buffer.append("\""); 86 if (tooltip!=null) { 87 buffer.append(" title=\""); 88 buffer.append(tooltip); 89 buffer.append("\""); 90 } 91 buffer.append(">"); 92 } 93 buffer.append(label); 94 if (styleClass != null) 95 buffer.append("</span>"); 96 } 97 if (cols != 0) { 98 buffer.append("</td>"); 99 } else { 100 buffer.append("<br>"); 101 } 102 103 } 104 108 public void beginField(StringBuffer buffer) throws JspException { 109 buffer.append("<tr><th colspan=\"").append(getSkin().getFieldInterface(getModel()).getColumnNumber()).append("\" class=\""); 111 buffer.append(styleClass); 112 buffer.append("\"><span class=\""); 113 buffer.append(styleClass); 114 buffer.append("\">"); 115 if (key!=null) buffer.append(getLabel()); else buffer.append(" "); 116 buffer.append("</span></th></tr><tr><td colspan=\"").append(getSkin().getFieldInterface(getModel()).getColumnNumber()).append("\" class=\""); 117 buffer.append(styleClass); 118 buffer.append("\">"); 119 } 120 public int doEndEditField() throws JspException { 121 if (cols != 0) { 123 TagUtils.write(pageContext, "</tr></table>"); 124 } 125 126 if (need_other) { 128 StringBuffer buffer = new StringBuffer (); 129 130 StringBuffer lc_otherField = new StringBuffer (); 131 cols = 0; 132 133 lc_otherField.append(" : <input type=\"text\" name=\""); 134 lc_otherField.append(otherProperty); 135 lc_otherField.append("\" value=\""); 136 if (otherValue != null) 137 lc_otherField.append(otherValue); 138 else 139 lc_otherField.append( 140 LayoutUtils.getBeanFromPageContext(pageContext, name, otherProperty)); 141 lc_otherField.append("\" class=\""); 142 lc_otherField.append(styleClass); 143 lc_otherField.append("\">"); 144 145 addChoice( 146 buffer, 147 OTHER_KEY, 148 LayoutUtils.getLabel(pageContext, OTHER_KEY, null) + lc_otherField.toString()); 149 TagUtils.write(pageContext, buffer.toString()); 150 } 151 152 return EVAL_PAGE; 154 } 155 public int doEndInspectField() throws JspException { 156 if (cols != 0) { 157 TagUtils.write(pageContext, "</tr></table>"); 158 } 159 160 if (need_other) { 162 StringBuffer buffer = new StringBuffer (); 163 164 StringBuffer lc_otherField = new StringBuffer (); 165 cols = 0; 166 167 lc_otherField.append(" : "); 168 if (otherValue != null) 169 lc_otherField.append(otherValue); 170 else 171 lc_otherField.append( 172 LayoutUtils.getBeanFromPageContext(pageContext, name, otherProperty)); 173 174 addChoice( 175 buffer, 176 OTHER_KEY, 177 LayoutUtils.getLabel(pageContext, OTHER_KEY, null) + lc_otherField.toString()); 178 TagUtils.write(pageContext, buffer.toString()); 179 } 180 181 return EVAL_PAGE; 183 } 184 public int doStartEditField() throws JspException { 185 if (cols != 0) { 186 TagUtils.write(pageContext, "<table border=\"0\"><tr>"); 187 } 188 189 return EVAL_BODY_INCLUDE; 191 } 192 public int doStartInspectField() throws JspException { 193 if (cols != 0) { 194 TagUtils.write(pageContext, "<table border=\"0\"><tr>"); 195 } 196 197 return EVAL_BODY_INCLUDE; 199 } 200 205 public java.lang.String getOtherKey() { 206 return otherKey; 207 } 208 213 public java.lang.String getOtherProperty() { 214 return otherProperty; 215 } 216 221 public java.lang.String getOtherValue() { 222 return otherValue; 223 } 224 protected void reset() { 225 super.reset(); 226 index = 0; 227 need_other = false; 228 } 229 public void release() { 230 super.release(); 231 cols = 0; 232 233 name = Constants.BEAN_KEY; 234 235 otherKey = "struts.layout.other"; 236 otherValue = null; 237 otherProperty = null; 238 } 239 public void setCols(String cols) throws JspException { 240 try { 241 this.cols = Integer.parseInt(cols); 242 if (this.cols<0) throw new NumberFormatException (); 243 } catch(NumberFormatException e) { 244 throw new JspException ("cols must be a positive integer. Actual value is: " + cols); 245 } 246 } 247 252 public void setOtherKey(java.lang.String newOtherKey) { 253 otherKey = newOtherKey; 254 need_other = true; 255 } 256 261 public void setOtherProperty(java.lang.String newOtherProperty) { 262 otherProperty = newOtherProperty; 263 need_other = true; 264 } 265 270 public void setOtherValue(java.lang.String newOtherValue) { 271 otherValue = newOtherValue; 272 need_other = true; 273 } 274 278 public String getAccesskey() { 279 return accesskey; 280 } 281 282 286 public void setAccesskey(String accesskey) { 287 this.accesskey = accesskey; 288 } 289 290 294 public String getMaxlength() { 295 return maxlength; 296 } 297 298 302 public void setMaxlength(String maxlength) { 303 this.maxlength = maxlength; 304 } 305 306 310 public String getOnblur() { 311 return onblur; 312 } 313 314 318 public void setOnblur(String onblur) { 319 this.onblur = onblur; 320 } 321 322 326 public String getOnclick() { 327 return onclick; 328 } 329 330 334 public void setOnclick(String onclick) { 335 this.onclick = onclick; 336 } 337 338 342 public String getOndblclick() { 343 return ondblclick; 344 } 345 346 350 public void setOndblclick(String ondblclick) { 351 this.ondblclick = ondblclick; 352 } 353 354 358 public String getOnfocus() { 359 return onfocus; 360 } 361 362 366 public void setOnfocus(String onfocus) { 367 this.onfocus = onfocus; 368 } 369 370 374 public String getOnkeydown() { 375 return onkeydown; 376 } 377 378 382 public void setOnkeydown(String onkeydown) { 383 this.onkeydown = onkeydown; 384 } 385 386 390 public String getOnkeyup() { 391 return onkeyup; 392 } 393 394 398 public void setOnkeyup(String onkeyup) { 399 this.onkeyup = onkeyup; 400 } 401 402 406 public String getOnkeypress() { 407 return onkeypress; 408 } 409 410 414 public void setOnkeypress(String onkeypress) { 415 this.onkeypress = onkeypress; 416 } 417 418 422 public String getOnmouseup() { 423 return onmouseup; 424 } 425 426 430 public void setOnmouseup(String onmouseup) { 431 this.onmouseup = onmouseup; 432 } 433 434 438 public String getOnmouseout() { 439 return onmouseout; 440 } 441 442 446 public void setOnmouseout(String onmouseout) { 447 this.onmouseout = onmouseout; 448 } 449 450 454 public String getOnmousemove() { 455 return onmousemove; 456 } 457 458 462 public void setOnmousemove(String onmousemove) { 463 this.onmousemove = onmousemove; 464 } 465 466 470 public String getOnmouseover() { 471 return onmouseover; 472 } 473 474 478 public void setOnmouseover(String onmouseover) { 479 this.onmouseover = onmouseover; 480 } 481 482 486 public String getOnmousedown() { 487 return onmousedown; 488 } 489 490 494 public void setOnmousedown(String onmousedown) { 495 this.onmousedown = onmousedown; 496 } 497 498 502 public String getOnchange() { 503 return onchange; 504 } 505 506 510 public void setOnchange(String onchange) { 511 this.onchange = onchange; 512 } 513 } 514 | Popular Tags |