KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > inversoft > verge > mvc > view > jsp > model > TextAreaTag


1 /*
2  * Copyright (c) 2003, Inversoft
3  *
4  * This software is distribuable under the GNU Lesser General Public License.
5  * For more information visit gnu.org.
6  */

7 package com.inversoft.verge.mvc.view.jsp.model;
8
9
10 import javax.servlet.jsp.JspException JavaDoc;
11
12 import com.inversoft.verge.mvc.model.ModelResolution;
13
14
15 /**
16  * This class is the HTML textarea input tag.
17  *
18  * @author Brian Pontarelli
19  */

20 public class TextAreaTag extends com.inversoft.verge.mvc.view.jsp.html.TextAreaTag {
21
22     protected ModelResolution modelResolution;
23
24
25     /**
26      * Initializes the tag by checking that the tag is inside a form tag
27      *
28      * @throws JspException If this tag is not inside a form tag
29      */

30     public void initialize() throws JspException JavaDoc {
31
32         // Initialize the parent reference
33
super.initialize();
34         super.initializeKeyProperty();
35
36         modelResolution = ModelHelper.getModelResolution(key, property, pageContext);
37         if (modelResolution == null) {
38             throw new JspException JavaDoc("Invalid model definition: " + getModel());
39         }
40     }
41
42     /**
43      * Overrides the doAfterBody so that the bean's value can be used if it is
44      * not null. If the bean's value is not null, it is used. Otherwise the body
45      * content is used.
46      */

47     public int doAfterBody() throws JspException JavaDoc {
48
49         Object JavaDoc bean = modelResolution.getModel();
50         assert (bean != null) : "bean == null";
51
52         Object JavaDoc value = null;
53         if (isGetValue()) {
54             value = ModelHelper.getValue(modelResolution, pageContext);
55         }
56
57         if (value != null) {
58             localText = value.toString();
59         } else {
60             super.doAfterBody();
61         }
62
63         return SKIP_BODY;
64     }
65
66     /**
67      * Overrides the renderTextAreaTag and determines if the model object contains
68      * any value and whether or not this vlaue is used for the text area tag.
69      *
70      * @param buf The StringBuffer passed to the super call
71      * @param text The value that is used in liew of the model's value
72      * if the model's value is null.
73      * @throws JspException If there was any problem getting the model's value
74      */

75     protected void createTextAreaTag(StringBuffer JavaDoc buf, String JavaDoc id, String JavaDoc name,
76             String JavaDoc text)
77     throws JspException JavaDoc {
78         Object JavaDoc bean = modelResolution.getModel();
79         assert (bean != null) : "bean == null";
80
81         if (isGetValue()) {
82             Object JavaDoc value = ModelHelper.getValue(modelResolution, pageContext);
83             if (value != null) {
84                 text = value.toString();
85             }
86         }
87
88
89         super.createTextAreaTag(buf, id, name, text);
90     }
91
92     /**
93      * Outputs the extra model information
94      *
95      * @return Always returns EVAL_PAGE
96      */

97     public int doEndTag() throws JspException JavaDoc {
98         super.doEndTag();
99         if (isSetValue()) {
100             ModelHelper.outputModelExtra(modelResolution.getMetaData(), localName,
101                 pageContext);
102         }
103
104         return EVAL_PAGE;
105     }
106 }
Popular Tags