KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > fr > improve > struts > taglib > layout > field > AbstractSelectTag


1 package fr.improve.struts.taglib.layout.field;
2
3 import javax.servlet.jsp.JspException JavaDoc;
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 /**
11  * Superclass of the radios and checkboxes tag.
12  * @author: JeanNoel Ribette
13  */

14 public abstract class AbstractSelectTag extends AbstractLayoutFieldTag implements ChoiceTag {
15     protected String JavaDoc accesskey;
16     protected String JavaDoc maxlength;
17     protected String JavaDoc onblur;
18     protected String JavaDoc onclick;
19     protected String JavaDoc ondblclick;
20     protected String JavaDoc onfocus;
21     protected String JavaDoc onkeydown;
22     protected String JavaDoc onkeyup;
23     protected String JavaDoc onkeypress;
24     protected String JavaDoc onmouseup;
25     protected String JavaDoc onmouseout;
26     protected String JavaDoc onmousemove;
27     protected String JavaDoc onmouseover;
28     protected String JavaDoc onmousedown;
29     protected String JavaDoc onchange;
30     
31     /**
32      * Numbers of cols in the table
33      */

34     protected int cols = 0;
35     protected int index = 0;
36
37     /**
38      * special default values for open selection<br>
39      * if one choice value equals to this value, a text input field is added after the select list.
40      */

41     public static final String JavaDoc OTHER_KEY = "struts.layout.other";
42     protected String JavaDoc otherKey = "struts.layout.other";
43     protected boolean need_other = false;
44     protected String JavaDoc otherProperty;
45     protected String JavaDoc otherValue;
46     public AbstractSelectTag() {
47         name = Constants.BEAN_KEY;
48     }
49     /**
50      * Implemanted by subclasses (CheckboxesTag & RadiosTag).<br>
51      * This method should print into the buffer the html code responsible for adding the value.
52      * @return true if the value is pre-selected, false otherwise.
53      */

54     public abstract boolean add1Choice(StringBuffer JavaDoc sb, String JavaDoc value) throws JspException JavaDoc ;
55     
56     /**
57      * This method will be call by the &lt;layout:option&gt; and &lt;layout:options&gt; tag to add a choice.
58      */

59     public final void addChoice(StringBuffer JavaDoc out_buffer, Choice in_choice) throws JspException JavaDoc {
60         addChoice(out_buffer, in_choice.getChoiceValue(), in_choice.getChoiceLabel(), in_choice.getChoiceTooltip());
61     }
62     
63     public final void addChoice(StringBuffer JavaDoc buffer, String JavaDoc value, String JavaDoc label) throws JspException JavaDoc {
64         addChoice(buffer, value, label, null);
65     }
66     
67 protected final void addChoice(StringBuffer JavaDoc buffer, String JavaDoc value, String JavaDoc label, String JavaDoc tooltip) throws JspException JavaDoc {
68     StringBuffer JavaDoc valueBuffer = new StringBuffer JavaDoc();
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     /**
105      * Render the name of the field
106      * The field value can be append in the stringbuffer just after calling this method
107      */

108     public void beginField(StringBuffer JavaDoc buffer) throws JspException JavaDoc {
109     // PENDING
110
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("&nbsp;");
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 JavaDoc {
121     // Close the table.
122
if (cols != 0) {
123         TagUtils.write(pageContext, "</tr></table>");
124     }
125
126     // Valeur autre.
127
if (need_other) {
128         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
129
130         StringBuffer JavaDoc lc_otherField = new StringBuffer JavaDoc();
131         cols = 0;
132
133         lc_otherField.append("&nbsp;: <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     // Continue processing this page
153
return EVAL_PAGE;
154 }
155 public int doEndInspectField() throws JspException JavaDoc {
156     if (cols != 0) {
157         TagUtils.write(pageContext, "</tr></table>");
158     }
159
160     // Valeur autre.
161
if (need_other) {
162         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
163
164         StringBuffer JavaDoc lc_otherField = new StringBuffer JavaDoc();
165         cols = 0;
166
167         lc_otherField.append("&nbsp;: ");
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     // Continue processing this page
182
return EVAL_PAGE;
183 }
184 public int doStartEditField() throws JspException JavaDoc {
185     if (cols != 0) {
186         TagUtils.write(pageContext, "<table border=\"0\"><tr>");
187     }
188
189     // Continue processing this page
190
return EVAL_BODY_INCLUDE;
191 }
192 public int doStartInspectField() throws JspException JavaDoc {
193     if (cols != 0) {
194         TagUtils.write(pageContext, "<table border=\"0\"><tr>");
195     }
196
197     // Continue processing this page
198
return EVAL_BODY_INCLUDE;
199 }
200 /**
201  * Insert the method's description here.
202  * Creation date: (07/09/2001 10:27:22)
203  * @return java.lang.String
204  */

205 public java.lang.String JavaDoc getOtherKey() {
206     return otherKey;
207 }
208 /**
209  * Insert the method's description here.
210  * Creation date: (07/09/2001 10:27:22)
211  * @return java.lang.String
212  */

213 public java.lang.String JavaDoc getOtherProperty() {
214     return otherProperty;
215 }
216 /**
217  * Insert the method's description here.
218  * Creation date: (07/09/2001 10:27:22)
219  * @return java.lang.String
220  */

221 public java.lang.String JavaDoc 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 JavaDoc cols) throws JspException JavaDoc {
240         try {
241             this.cols = Integer.parseInt(cols);
242             if (this.cols<0) throw new NumberFormatException JavaDoc();
243         } catch(NumberFormatException JavaDoc e) {
244             throw new JspException JavaDoc("cols must be a positive integer. Actual value is: " + cols);
245         }
246     }
247 /**
248  * Insert the method's description here.
249  * Creation date: (07/09/2001 10:27:22)
250  * @param newOtherKey java.lang.String
251  */

252 public void setOtherKey(java.lang.String JavaDoc newOtherKey) {
253     otherKey = newOtherKey;
254     need_other = true;
255 }
256 /**
257  * Insert the method's description here.
258  * Creation date: (07/09/2001 10:27:22)
259  * @param newOtherProperty java.lang.String
260  */

261 public void setOtherProperty(java.lang.String JavaDoc newOtherProperty) {
262     otherProperty = newOtherProperty;
263     need_other = true;
264 }
265 /**
266  * Insert the method's description here.
267  * Creation date: (07/09/2001 10:27:22)
268  * @param newOtherValue java.lang.String
269  */

270 public void setOtherValue(java.lang.String JavaDoc newOtherValue) {
271     otherValue = newOtherValue;
272     need_other = true;
273 }
274     /**
275      * Gets the accessKey.
276      * @return Returns a String
277      */

278     public String JavaDoc getAccesskey() {
279         return accesskey;
280     }
281
282     /**
283      * Sets the accessKey.
284      * @param accessKey The accessKey to set
285      */

286     public void setAccesskey(String JavaDoc accesskey) {
287         this.accesskey = accesskey;
288     }
289
290     /**
291      * Gets the maxlength.
292      * @return Returns a String
293      */

294     public String JavaDoc getMaxlength() {
295         return maxlength;
296     }
297
298     /**
299      * Sets the maxlength.
300      * @param maxlength The maxlength to set
301      */

302     public void setMaxlength(String JavaDoc maxlength) {
303         this.maxlength = maxlength;
304     }
305
306     /**
307      * Gets the onblur.
308      * @return Returns a String
309      */

310     public String JavaDoc getOnblur() {
311         return onblur;
312     }
313
314     /**
315      * Sets the onblur.
316      * @param onblur The onblur to set
317      */

318     public void setOnblur(String JavaDoc onblur) {
319         this.onblur = onblur;
320     }
321
322     /**
323      * Gets the onclick.
324      * @return Returns a String
325      */

326     public String JavaDoc getOnclick() {
327         return onclick;
328     }
329
330     /**
331      * Sets the onclick.
332      * @param onclick The onclick to set
333      */

334     public void setOnclick(String JavaDoc onclick) {
335         this.onclick = onclick;
336     }
337
338     /**
339      * Gets the ondblclick.
340      * @return Returns a String
341      */

342     public String JavaDoc getOndblclick() {
343         return ondblclick;
344     }
345
346     /**
347      * Sets the ondblclick.
348      * @param ondblclick The ondblclick to set
349      */

350     public void setOndblclick(String JavaDoc ondblclick) {
351         this.ondblclick = ondblclick;
352     }
353
354     /**
355      * Gets the onfocus.
356      * @return Returns a String
357      */

358     public String JavaDoc getOnfocus() {
359         return onfocus;
360     }
361
362     /**
363      * Sets the onfocus.
364      * @param onfocus The onfocus to set
365      */

366     public void setOnfocus(String JavaDoc onfocus) {
367         this.onfocus = onfocus;
368     }
369
370     /**
371      * Gets the onkeydown.
372      * @return Returns a String
373      */

374     public String JavaDoc getOnkeydown() {
375         return onkeydown;
376     }
377
378     /**
379      * Sets the onkeydown.
380      * @param onkeydown The onkeydown to set
381      */

382     public void setOnkeydown(String JavaDoc onkeydown) {
383         this.onkeydown = onkeydown;
384     }
385
386     /**
387      * Gets the onkeyup.
388      * @return Returns a String
389      */

390     public String JavaDoc getOnkeyup() {
391         return onkeyup;
392     }
393
394     /**
395      * Sets the onkeyup.
396      * @param onkeyup The onkeyup to set
397      */

398     public void setOnkeyup(String JavaDoc onkeyup) {
399         this.onkeyup = onkeyup;
400     }
401
402     /**
403      * Gets the onkeypress.
404      * @return Returns a String
405      */

406     public String JavaDoc getOnkeypress() {
407         return onkeypress;
408     }
409
410     /**
411      * Sets the onkeypress.
412      * @param onkeypress The onkeypress to set
413      */

414     public void setOnkeypress(String JavaDoc onkeypress) {
415         this.onkeypress = onkeypress;
416     }
417
418     /**
419      * Gets the onmouseup.
420      * @return Returns a String
421      */

422     public String JavaDoc getOnmouseup() {
423         return onmouseup;
424     }
425
426     /**
427      * Sets the onmouseup.
428      * @param onmouseup The onmouseup to set
429      */

430     public void setOnmouseup(String JavaDoc onmouseup) {
431         this.onmouseup = onmouseup;
432     }
433
434     /**
435      * Gets the onmouseout.
436      * @return Returns a String
437      */

438     public String JavaDoc getOnmouseout() {
439         return onmouseout;
440     }
441
442     /**
443      * Sets the onmouseout.
444      * @param onmouseout The onmouseout to set
445      */

446     public void setOnmouseout(String JavaDoc onmouseout) {
447         this.onmouseout = onmouseout;
448     }
449
450     /**
451      * Gets the onmousemove.
452      * @return Returns a String
453      */

454     public String JavaDoc getOnmousemove() {
455         return onmousemove;
456     }
457
458     /**
459      * Sets the onmousemove.
460      * @param onmousemove The onmousemove to set
461      */

462     public void setOnmousemove(String JavaDoc onmousemove) {
463         this.onmousemove = onmousemove;
464     }
465
466     /**
467      * Gets the onmouseover.
468      * @return Returns a String
469      */

470     public String JavaDoc getOnmouseover() {
471         return onmouseover;
472     }
473
474     /**
475      * Sets the onmouseover.
476      * @param onmouseover The onmouseover to set
477      */

478     public void setOnmouseover(String JavaDoc onmouseover) {
479         this.onmouseover = onmouseover;
480     }
481
482     /**
483      * Gets the onmousedown.
484      * @return Returns a String
485      */

486     public String JavaDoc getOnmousedown() {
487         return onmousedown;
488     }
489
490     /**
491      * Sets the onmousedown.
492      * @param onmousedown The onmousedown to set
493      */

494     public void setOnmousedown(String JavaDoc onmousedown) {
495         this.onmousedown = onmousedown;
496     }
497
498     /**
499      * Gets the onchange.
500      * @return Returns a String
501      */

502     public String JavaDoc getOnchange() {
503         return onchange;
504     }
505
506     /**
507      * Sets the onchange.
508      * @param onchange The onchange to set
509      */

510     public void setOnchange(String JavaDoc onchange) {
511         this.onchange = onchange;
512     }
513 }
514
Popular Tags