KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > inversoft > verge > mvc > view > jsp > html > 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.html;
8
9
10 import java.io.IOException JavaDoc;
11
12 import javax.servlet.jsp.JspException JavaDoc;
13
14 import org.apache.log4j.Logger;
15
16 import com.inversoft.verge.mvc.view.HtmlConstants;
17 import com.inversoft.verge.mvc.view.HtmlViewToolkit;
18 import com.inversoft.verge.mvc.view.jsp.JspTools;
19
20
21 /**
22  * This class is the HTML textarea input tag.
23  *
24  * @author Brian Pontarelli
25  */

26 public class TextAreaTag extends InputTag {
27
28     /**
29      * This classes logger
30      */

31     private static final Logger logger = Logger.getLogger(TextAreaTag.class);
32
33
34     private String JavaDoc text;
35     protected String JavaDoc localText;
36     private Integer JavaDoc rows;
37     private Integer JavaDoc cols;
38
39
40     /**
41      * Retrieves the tag's rows attribute
42      *
43      * @return Returns the tag's rows attribute
44      */

45     public Integer JavaDoc getRows() {
46         return rows;
47     }
48
49     /**
50      * Populates the tag's rows attribute
51      *
52      * @param rows The value of the tag's rows attribute
53      */

54     public void setRows(Integer JavaDoc rows) {
55         this.rows = rows;
56     }
57
58     /**
59      * Retrieves the tag's cols attribute
60      *
61      * @return Returns the tag's cols attribute
62      */

63     public Integer JavaDoc getCols() {
64         return cols;
65     }
66
67     /**
68      * Populates the tag's cols attribute
69      *
70      * @param cols The value of the tag's cols attribute
71      */

72     public void setCols(Integer JavaDoc cols) {
73         this.cols = cols;
74     }
75
76     /**
77      * Retrieves the tag's text attribute
78      *
79      * @return Returns the tag's text attribute
80      */

81     public String JavaDoc getText() {
82         return text;
83     }
84
85     /**
86      * Populates the tag's text attribute
87      *
88      * @param text The value of the tag's text attribute
89      */

90     public void setText(String JavaDoc text) {
91         this.text = text;
92     }
93
94     /**
95      * Initialize the tag by expanding the text if need be
96      */

97     protected void initialize() throws JspException JavaDoc {
98         super.initialize();
99
100         localText = text;
101         if (!JspTools.JSP_20) {
102             localText = (String JavaDoc) JspTools.expand("text", text, String JavaDoc.class,
103                 this, pageContext);
104         }
105
106         attributes.put(HtmlConstants.ROWS, rows);
107         attributes.put(HtmlConstants.COLS, cols);
108     }
109
110     /**
111      * Generates the HTML tag
112      */

113     public int doStartTag() throws JspException JavaDoc {
114
115         // Initialize the parent reference and the bean reference
116
initialize();
117
118         return EVAL_BODY_BUFFERED;
119     }
120
121     /**
122      * Expands any body content
123      */

124     public int doAfterBody() throws JspException JavaDoc {
125         if (bodyContent != null) {
126             localText = bodyContent.getString();
127             if (localText != null && JspTools.JSP_20) {
128                 localText = (String JavaDoc) JspTools.expand("text", localText,
129                     String JavaDoc.class, this, pageContext);
130             }
131         }
132
133         return SKIP_BODY;
134     }
135
136     /**
137      * Generate the HTML tag
138      *
139      * @see javax.servlet.jsp.tagext.Tag#doStartTag()
140      */

141     public int doEndTag() throws JspException JavaDoc {
142
143         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
144         createTextAreaTag(buf, getId(), localName, localText);
145
146         try {
147             pageContext.getOut().print(buf.toString());
148         } catch (IOException JavaDoc ioe) {
149             throw new JspException JavaDoc(ioe.toString());
150         }
151
152         return EVAL_PAGE;
153     }
154
155     /**
156      * Does the work of render the HTML for this textarea tag. This HTML is
157      * appended to the given StringBuffer.
158      *
159      * @param buf The StringBuffer to appended to
160      * @param id The id of the tag
161      * @param name The name of the tag
162      * @param text The outputText which is the body of the generated
163      * textarea tag or from the text attribute
164      * @throws JspException For overriding sub-classes
165      */

166     protected void createTextAreaTag(StringBuffer JavaDoc buf, String JavaDoc id, String JavaDoc name,
167         String JavaDoc text)
168     throws JspException JavaDoc {
169         HtmlViewToolkit.createTextAreaTag(buf, id, name, text, attributes,
170             singleAttrs);
171
172         if (logger.isDebugEnabled()) {
173             logger.debug("The text area tag: " + buf.toString());
174         }
175     }
176 }
Popular Tags