KickJava   Java API By Example, From Geeks To Geeks.

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


1 package fr.improve.struts.taglib.layout.field;
2
3 import javax.servlet.jsp.JspException JavaDoc;
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 /**
13  * Abstract class for the usual input fields (text, textarea, password and checkbox). <br>
14  *
15  * The content of the tag is displayed after the input field
16  * so that buttons or other elements can be added
17  *
18  * @author: Jean-Noel Ribette
19  **/

20 public abstract class AbstractFieldTag extends AbstractLayoutFieldTag {
21     /**
22      * The fieldTag from the Struts html taglib.
23      */

24     protected BaseHandlerTag fieldTag;
25
26     /**
27      * The fieldTag parameters.
28      */

29     protected String JavaDoc value;
30     protected String JavaDoc accept;
31     protected String JavaDoc cols;
32     protected String JavaDoc maxlength;
33     protected String JavaDoc rows;
34     protected String JavaDoc size;
35     protected String JavaDoc accesskey;
36     protected String JavaDoc onblur;
37     protected String JavaDoc onclick;
38     protected String JavaDoc ondblclick;
39     protected String JavaDoc onfocus;
40     protected String JavaDoc onkeydown;
41     protected String JavaDoc onkeyup;
42     protected String JavaDoc onkeypress;
43     protected String JavaDoc onmouseup;
44     protected String JavaDoc onmouseout;
45     protected String JavaDoc onmousemove;
46     protected String JavaDoc onmouseover;
47     protected String JavaDoc onmousedown;
48     
49     protected String JavaDoc tabIndex;
50     protected String JavaDoc onchange;
51     protected String JavaDoc onselect;
52     protected boolean filter = true;
53     
54     /**
55      * The field value set in the jsp.
56      */

57     protected String JavaDoc jspValue;
58     
59     public AbstractFieldTag() {
60         super();
61         name = Constants.BEAN_KEY;
62     }
63     
64     
65 protected void doAfterValue() throws JspException JavaDoc {
66     // default implentation doing nothing.
67
}
68 /**
69  * This method is called before displaying the value.
70  * This is the place to write something before the value, and set the fieldTag value.
71  * @return true - process the tag<br>
72  * false - skip the tag
73  */

74 protected abstract boolean doBeforeValue() throws JspException JavaDoc;
75 public int doEndEditField() throws JspException JavaDoc {
76     return EVAL_PAGE;
77 }
78 public int doEndInspectField() throws JspException JavaDoc {
79     return EVAL_PAGE;
80 }
81 public int doStartEditField() throws JspException JavaDoc {
82     // Maybe do something before dispaying the value
83
if (!doBeforeValue()) return SKIP_BODY;
84
85     // Initialize the tag
86
if (fieldTag == null) throw new JspException JavaDoc(getClass().getName() + " should really set the fieldTag value in doBeforeValue() !");
87     
88     // copy properties
89
copyProperties(fieldTag);
90     
91     //set the name of the javascript to use
92
boolean check = isRequired();
93     if (check) {
94         StringBuffer JavaDoc lc_buffer = new StringBuffer JavaDoc("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 JavaDoc {
110     // PENDING nice, but not that fast.
111
// LayoutUtils.copyProperties(in_dest, this);
112

113     // PENDING not nice, but that fast.
114
fieldTag.setAccesskey(getAccesskey());
115     // alt
116
// altkey
117
//fieldTag.setBundle(getBundle()); only used in Struts 1.1 for altKey and titleKey, which are not use here.
118
fieldTag.setDisabled(isDisabledAsBoolean());
119     fieldTag.setId(getId());
120     // indexed
121
// locale
122
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     // title key.
145

146 }
147 public int doStartInspectField() throws JspException JavaDoc {
148     // Maybe do something before dispaying the value.
149
if (!doBeforeValue()) return SKIP_BODY;
150         
151     Object JavaDoc lc_value = getFieldValue();
152     if (lc_value!=null) {
153         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
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 JavaDoc getAccept() {
171     return accept;
172 }
173 public String JavaDoc getCols() {
174     return cols;
175 }
176     protected Object JavaDoc getFieldValue() throws JspException JavaDoc{
177         if (value!=null) return value;
178         return LayoutUtils.getBeanFromPageContext(pageContext, name, property);
179     }
180 public String JavaDoc getMaxlength() {
181     return maxlength;
182 }
183 public String JavaDoc getRows() {
184     return rows;
185 }
186 public String JavaDoc getSize() {
187     return cols;
188 }
189 public BaseHandlerTag getFieldTag() {
190     return fieldTag;
191 }
192 public String JavaDoc getValue() {
193     try {
194         Object JavaDoc lc_value = getFieldValue();
195         if (lc_value != null) return lc_value.toString();
196     } catch (JspException JavaDoc e) {
197         // PENDING
198
}
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 JavaDoc accept) {
238     this.accept = accept;
239 }
240 /**
241  * Insert the method's description here.
242  * Creation date: (19/02/01 11:29:27)
243  * @param newCols int
244  */

245 public void setCols(String JavaDoc newCols) {
246     cols = newCols;
247 }
248 public void setMaxlength(String JavaDoc maxlength) {
249     this.maxlength = maxlength;
250 }
251 /**
252  * Insert the method's description here.
253  * Creation date: (19/02/01 11:29:27)
254  * @param newRows int
255  */

256 public void setRows(String JavaDoc newRows) {
257     rows = newRows;
258 }
259 /**
260  * Insert the method's description here.
261  * Creation date: (19/02/01 11:29:27)
262  * @param newSize int
263  */

264 public void setSize(String JavaDoc newSize) {
265     cols = newSize;
266 }
267 public void setValue(String JavaDoc value) {
268     this.value = value;
269 }
270     /**
271      * Gets the accessKey.
272      * @return Returns a String
273      */

274     public String JavaDoc getAccesskey() {
275         return accesskey;
276     }
277
278     /**
279      * Sets the accessKey.
280      * @param accessKey The accessKey to set
281      */

282     public void setAccesskey(String JavaDoc accesskey) {
283         this.accesskey = accesskey;
284     }
285
286     /**
287      * Gets the onblur.
288      * @return Returns a String
289      */

290     public String JavaDoc getOnblur() {
291         return onblur;
292     }
293
294     /**
295      * Sets the onblur.
296      * @param onblur The onblur to set
297      */

298     public void setOnblur(String JavaDoc onblur) {
299         this.onblur = onblur;
300     }
301
302     /**
303      * Gets the onclick.
304      * @return Returns a String
305      */

306     public String JavaDoc getOnclick() {
307         return onclick;
308     }
309
310     /**
311      * Sets the onclick.
312      * @param onclick The onclick to set
313      */

314     public void setOnclick(String JavaDoc onclick) {
315         this.onclick = onclick;
316     }
317
318     /**
319      * Gets the ondblclick.
320      * @return Returns a String
321      */

322     public String JavaDoc getOndblclick() {
323         return ondblclick;
324     }
325
326     /**
327      * Sets the ondblclick.
328      * @param ondblclick The ondblclick to set
329      */

330     public void setOndblclick(String JavaDoc ondblclick) {
331         this.ondblclick = ondblclick;
332     }
333
334     /**
335      * Gets the onkeyup.
336      * @return Returns a String
337      */

338     public String JavaDoc getOnkeyup() {
339         return onkeyup;
340     }
341
342     /**
343      * Sets the onkeyup.
344      * @param onkeyup The onkeyup to set
345      */

346     public void setOnkeyup(String JavaDoc onkeyup) {
347         this.onkeyup = onkeyup;
348     }
349
350     /**
351      * Gets the onkeydown.
352      * @return Returns a String
353      */

354     public String JavaDoc getOnkeydown() {
355         return onkeydown;
356     }
357
358     /**
359      * Sets the onkeydown.
360      * @param onkeydown The onkeydown to set
361      */

362     public void setOnkeydown(String JavaDoc onkeydown) {
363         this.onkeydown = onkeydown;
364     }
365
366     /**
367      * Gets the onfocus.
368      * @return Returns a String
369      */

370     public String JavaDoc getOnfocus() {
371         return onfocus;
372     }
373
374     /**
375      * Sets the onfocus.
376      * @param onfocus The onfocus to set
377      */

378     public void setOnfocus(String JavaDoc onfocus) {
379         this.onfocus = onfocus;
380     }
381
382     /**
383      * Gets the onkeypress.
384      * @return Returns a String
385      */

386     public String JavaDoc getOnkeypress() {
387         return onkeypress;
388     }
389
390     /**
391      * Sets the onkeypress.
392      * @param onkeypress The onkeypress to set
393      */

394     public void setOnkeypress(String JavaDoc onkeypress) {
395         this.onkeypress = onkeypress;
396     }
397
398     /**
399      * Gets the onmouseout.
400      * @return Returns a String
401      */

402     public String JavaDoc getOnmouseout() {
403         return onmouseout;
404     }
405
406     /**
407      * Sets the onmouseout.
408      * @param onmouseout The onmouseout to set
409      */

410     public void setOnmouseout(String JavaDoc onmouseout) {
411         this.onmouseout = onmouseout;
412     }
413
414     /**
415      * Gets the onmouseup.
416      * @return Returns a String
417      */

418     public String JavaDoc getOnmouseup() {
419         return onmouseup;
420     }
421
422     /**
423      * Sets the onmouseup.
424      * @param onmouseup The onmouseup to set
425      */

426     public void setOnmouseup(String JavaDoc onmouseup) {
427         this.onmouseup = onmouseup;
428     }
429
430     /**
431      * Gets the onmousemove.
432      * @return Returns a String
433      */

434     public String JavaDoc getOnmousemove() {
435         return onmousemove;
436     }
437
438     /**
439      * Sets the onmousemove.
440      * @param onmousemove The onmousemove to set
441      */

442     public void setOnmousemove(String JavaDoc onmousemove) {
443         this.onmousemove = onmousemove;
444     }
445
446     /**
447      * Gets the onmouseover.
448      * @return Returns a String
449      */

450     public String JavaDoc getOnmouseover() {
451         return onmouseover;
452     }
453
454     /**
455      * Sets the onmouseover.
456      * @param onmouseover The onmouseover to set
457      */

458     public void setOnmouseover(String JavaDoc onmouseover) {
459         this.onmouseover = onmouseover;
460     }
461
462     /**
463      * Gets the onmousedown.
464      * @return Returns a String
465      */

466     public String JavaDoc getOnmousedown() {
467         return onmousedown;
468     }
469
470     /**
471      * Sets the onmousedown.
472      * @param onmousedown The onmousedown to set
473      */

474     public void setOnmousedown(String JavaDoc onmousedown) {
475         this.onmousedown = onmousedown;
476     }
477
478     /**
479      * Gets the tabIndex.
480      * @return Returns a String
481      */

482     public String JavaDoc getTabindex() {
483         return tabIndex;
484     }
485
486     /**
487      * Sets the tabIndex.
488      * @param tabIndex The tabIndex to set
489      */

490     public void setTabindex(String JavaDoc tabIndex) {
491         this.tabIndex = tabIndex;
492     }
493
494     /**
495      * Gets the onselect.
496      * @return Returns a String
497      */

498     public String JavaDoc getOnselect() {
499         return onselect;
500     }
501
502     /**
503      * Sets the onselect.
504      * @param onselect The onselect to set
505      */

506     public void setOnselect(String JavaDoc onselect) {
507         this.onselect = onselect;
508     }
509
510     /**
511      * Gets the onchange.
512      * @return Returns a String
513      */

514     public String JavaDoc getOnchange() {
515         return onchange;
516     }
517
518     /**
519      * Sets the onchange.
520      * @param onchange The onchange to set
521      */

522     public void setOnchange(String JavaDoc onchange) {
523         this.onchange = onchange;
524     }
525
526     /**
527      * Sets the filter.
528      * @param filter The filter to set
529      */

530     public void setFilter(boolean filter) {
531         this.filter = filter;
532     }
533
534     /**
535      * Compute EL values.
536      */

537     protected void initDynamicValues() {
538         super.initDynamicValues();
539         
540         // compute the runtime value of the "value" attribute.
541
jspValue = value;
542         value = Expression.evaluate(jspValue, pageContext);
543     }
544 }
545
Popular Tags