001/*
002 * Copyright 2002-2018 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      https://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.web.servlet.tags.form;
018
019import javax.servlet.jsp.JspException;
020
021import org.springframework.lang.Nullable;
022
023/**
024 * The {@code <textarea>} tag renders an HTML 'textarea'.
025 *
026 * <p>
027 * <table>
028 * <caption>Attribute Summary</caption>
029 * <thead>
030 * <tr>
031 * <th class="colFirst">Attribute</th>
032 * <th class="colOne">Required?</th>
033 * <th class="colOne">Runtime Expression?</th>
034 * <th class="colLast">Description</th>
035 * </tr>
036 * </thead>
037 * <tbody>
038 * <tr class="altColor">
039 * <td><p>accesskey</p></td>
040 * <td><p>false</p></td>
041 * <td><p>true</p></td>
042 * <td><p>HTML Standard Attribute</p></td>
043 * </tr>
044 * <tr class="rowColor">
045 * <td><p>cols</p></td>
046 * <td><p>false</p></td>
047 * <td><p>true</p></td>
048 * <td><p>HTML Required Attribute</p></td>
049 * </tr>
050 * <tr class="altColor">
051 * <td><p>cssClass</p></td>
052 * <td><p>false</p></td>
053 * <td><p>true</p></td>
054 * <td><p>HTML Optional Attribute</p></td>
055 * </tr>
056 * <tr class="rowColor">
057 * <td><p>cssErrorClass</p></td>
058 * <td><p>false</p></td>
059 * <td><p>true</p></td>
060 * <td><p>HTML Optional Attribute. Used when the bound field has errors.</p></td>
061 * </tr>
062 * <tr class="altColor">
063 * <td><p>cssStyle</p></td>
064 * <td><p>false</p></td>
065 * <td><p>true</p></td>
066 * <td><p>HTML Optional Attribute</p></td>
067 * </tr>
068 * <tr class="rowColor">
069 * <td><p>dir</p></td>
070 * <td><p>false</p></td>
071 * <td><p>true</p></td>
072 * <td><p>HTML Standard Attribute</p></td>
073 * </tr>
074 * <tr class="altColor">
075 * <td><p>disabled</p></td>
076 * <td><p>false</p></td>
077 * <td><p>true</p></td>
078 * <td><p>HTML Optional Attribute. Setting the value of this attribute to 'true'
079 * will disable the HTML element.</p></td>
080 * </tr>
081 * <tr class="rowColor">
082 * <td><p>htmlEscape</p></td>
083 * <td><p>false</p></td>
084 * <td><p>true</p></td>
085 * <td><p>Enable/disable HTML escaping of rendered values.</p></td>
086 * </tr>
087 * <tr class="altColor">
088 * <td><p>id</p></td>
089 * <td><p>false</p></td>
090 * <td><p>true</p></td>
091 * <td><p>HTML Standard Attribute</p></td>
092 * </tr>
093 * <tr class="rowColor">
094 * <td><p>lang</p></td>
095 * <td><p>false</p></td>
096 * <td><p>true</p></td>
097 * <td><p>HTML Standard Attribute</p></td>
098 * </tr>
099 * <tr class="altColor">
100 * <td><p>onblur</p></td>
101 * <td><p>false</p></td>
102 * <td><p>true</p></td>
103 * <td><p>HTML Event Attribute</p></td>
104 * </tr>
105 * <tr class="rowColor">
106 * <td><p>onchange</p></td>
107 * <td><p>false</p></td>
108 * <td><p>true</p></td>
109 * <td><p>HTML Event Attribute</p></td>
110 * </tr>
111 * <tr class="altColor">
112 * <td><p>onclick</p></td>
113 * <td><p>false</p></td>
114 * <td><p>true</p></td>
115 * <td><p>HTML Event Attribute</p></td>
116 * </tr>
117 * <tr class="rowColor">
118 * <td><p>ondblclick</p></td>
119 * <td><p>false</p></td>
120 * <td><p>true</p></td>
121 * <td><p>HTML Event Attribute</p></td>
122 * </tr>
123 * <tr class="altColor">
124 * <td><p>onfocus</p></td>
125 * <td><p>false</p></td>
126 * <td><p>true</p></td>
127 * <td><p>HTML Event Attribute</p></td>
128 * </tr>
129 * <tr class="rowColor">
130 * <td><p>onkeydown</p></td>
131 * <td><p>false</p></td>
132 * <td><p>true</p></td>
133 * <td><p>HTML Event Attribute</p></td>
134 * </tr>
135 * <tr class="altColor">
136 * <td><p>onkeypress</p></td>
137 * <td><p>false</p></td>
138 * <td><p>true</p></td>
139 * <td><p>HTML Event Attribute</p></td>
140 * </tr>
141 * <tr class="rowColor">
142 * <td><p>onkeyup</p></td>
143 * <td><p>false</p></td>
144 * <td><p>true</p></td>
145 * <td><p>HTML Event Attribute</p></td>
146 * </tr>
147 * <tr class="altColor">
148 * <td><p>onmousedown</p></td>
149 * <td><p>false</p></td>
150 * <td><p>true</p></td>
151 * <td><p>HTML Event Attribute</p></td>
152 * </tr>
153 * <tr class="rowColor">
154 * <td><p>onmousemove</p></td>
155 * <td><p>false</p></td>
156 * <td><p>true</p></td>
157 * <td><p>HTML Event Attribute</p></td>
158 * </tr>
159 * <tr class="altColor">
160 * <td><p>onmouseout</p></td>
161 * <td><p>false</p></td>
162 * <td><p>true</p></td>
163 * <td><p>HTML Event Attribute</p></td>
164 * </tr>
165 * <tr class="rowColor">
166 * <td><p>onmouseover</p></td>
167 * <td><p>false</p></td>
168 * <td><p>true</p></td>
169 * <td><p>HTML Event Attribute</p></td>
170 * </tr>
171 * <tr class="altColor">
172 * <td><p>onmouseup</p></td>
173 * <td><p>false</p></td>
174 * <td><p>true</p></td>
175 * <td><p>HTML Event Attribute</p></td>
176 * </tr>
177 * <tr class="rowColor">
178 * <td><p>onselect</p></td>
179 * <td><p>false</p></td>
180 * <td><p>true</p></td>
181 * <td><p>HTML Event Attribute</p></td>
182 * </tr>
183 * <tr class="altColor">
184 * <td><p>path</p></td>
185 * <td><p>true</p></td>
186 * <td><p>true</p></td>
187 * <td><p>Path to property for data binding</p></td>
188 * </tr>
189 * <tr class="rowColor">
190 * <td><p>readonly</p></td>
191 * <td><p>false</p></td>
192 * <td><p>true</p></td>
193 * <td><p>HTML Optional Attribute. Setting the value of this attribute to 'true'
194 * will make the HTML element readonly.</p></td>
195 * </tr>
196 * <tr class="altColor">
197 * <td><p>rows</p></td>
198 * <td><p>false</p></td>
199 * <td><p>true</p></td>
200 * <td><p>HTML Required Attribute</p></td>
201 * </tr>
202 * <tr class="rowColor">
203 * <td><p>tabindex</p></td>
204 * <td><p>false</p></td>
205 * <td><p>true</p></td>
206 * <td><p>HTML Standard Attribute</p></td>
207 * </tr>
208 * <tr class="altColor">
209 * <td><p>title</p></td>
210 * <td><p>false</p></td>
211 * <td><p>true</p></td>
212 * <td><p>HTML Standard Attribute</p></td>
213 * </tr>
214 * </tbody>
215 * </table>
216 *
217 * @author Rob Harrop
218 * @author Juergen Hoeller
219 * @since 2.0
220 */
221@SuppressWarnings("serial")
222public class TextareaTag extends AbstractHtmlInputElementTag {
223
224        public static final String ROWS_ATTRIBUTE = "rows";
225
226        public static final String COLS_ATTRIBUTE = "cols";
227
228        public static final String ONSELECT_ATTRIBUTE = "onselect";
229
230
231        @Nullable
232        private String rows;
233
234        @Nullable
235        private String cols;
236
237        @Nullable
238        private String onselect;
239
240
241        /**
242         * Set the value of the '{@code rows}' attribute.
243         * May be a runtime expression.
244         */
245        public void setRows(String rows) {
246                this.rows = rows;
247        }
248
249        /**
250         * Get the value of the '{@code rows}' attribute.
251         */
252        @Nullable
253        protected String getRows() {
254                return this.rows;
255        }
256
257        /**
258         * Set the value of the '{@code cols}' attribute.
259         * May be a runtime expression.
260         */
261        public void setCols(String cols) {
262                this.cols = cols;
263        }
264
265        /**
266         * Get the value of the '{@code cols}' attribute.
267         */
268        @Nullable
269        protected String getCols() {
270                return this.cols;
271        }
272
273        /**
274         * Set the value of the '{@code onselect}' attribute.
275         * May be a runtime expression.
276         */
277        public void setOnselect(String onselect) {
278                this.onselect = onselect;
279        }
280
281        /**
282         * Get the value of the '{@code onselect}' attribute.
283         */
284        @Nullable
285        protected String getOnselect() {
286                return this.onselect;
287        }
288
289
290        @Override
291        protected int writeTagContent(TagWriter tagWriter) throws JspException {
292                tagWriter.startTag("textarea");
293                writeDefaultAttributes(tagWriter);
294                writeOptionalAttribute(tagWriter, ROWS_ATTRIBUTE, getRows());
295                writeOptionalAttribute(tagWriter, COLS_ATTRIBUTE, getCols());
296                writeOptionalAttribute(tagWriter, ONSELECT_ATTRIBUTE, getOnselect());
297                String value = getDisplayString(getBoundValue(), getPropertyEditor());
298                tagWriter.appendValue("\r\n" + processFieldValue(getName(), value, "textarea"));
299                tagWriter.endTag();
300                return SKIP_BODY;
301        }
302
303}