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 021/** 022 * Databinding-aware JSP tag for rendering an HTML '{@code textarea}'. 023 * 024 * @author Rob Harrop 025 * @author Juergen Hoeller 026 * @since 2.0 027 */ 028@SuppressWarnings("serial") 029public class TextareaTag extends AbstractHtmlInputElementTag { 030 031 public static final String ROWS_ATTRIBUTE = "rows"; 032 033 public static final String COLS_ATTRIBUTE = "cols"; 034 035 public static final String ONSELECT_ATTRIBUTE = "onselect"; 036 037 @Deprecated 038 public static final String READONLY_ATTRIBUTE = "readonly"; 039 040 041 private String rows; 042 043 private String cols; 044 045 private String onselect; 046 047 048 /** 049 * Set the value of the '{@code rows}' attribute. 050 * May be a runtime expression. 051 */ 052 public void setRows(String rows) { 053 this.rows = rows; 054 } 055 056 /** 057 * Get the value of the '{@code rows}' attribute. 058 */ 059 protected String getRows() { 060 return this.rows; 061 } 062 063 /** 064 * Set the value of the '{@code cols}' attribute. 065 * May be a runtime expression. 066 */ 067 public void setCols(String cols) { 068 this.cols = cols; 069 } 070 071 /** 072 * Get the value of the '{@code cols}' attribute. 073 */ 074 protected String getCols() { 075 return this.cols; 076 } 077 078 /** 079 * Set the value of the '{@code onselect}' attribute. 080 * May be a runtime expression. 081 */ 082 public void setOnselect(String onselect) { 083 this.onselect = onselect; 084 } 085 086 /** 087 * Get the value of the '{@code onselect}' attribute. 088 */ 089 protected String getOnselect() { 090 return this.onselect; 091 } 092 093 094 @Override 095 protected int writeTagContent(TagWriter tagWriter) throws JspException { 096 tagWriter.startTag("textarea"); 097 writeDefaultAttributes(tagWriter); 098 writeOptionalAttribute(tagWriter, ROWS_ATTRIBUTE, getRows()); 099 writeOptionalAttribute(tagWriter, COLS_ATTRIBUTE, getCols()); 100 writeOptionalAttribute(tagWriter, ONSELECT_ATTRIBUTE, getOnselect()); 101 String value = getDisplayString(getBoundValue(), getPropertyEditor()); 102 tagWriter.appendValue("\r\n" + processFieldValue(getName(), value, "textarea")); 103 tagWriter.endTag(); 104 return SKIP_BODY; 105 } 106 107}