1 /**
2 * Copyright 2005-2013 The Kuali Foundation
3 *
4 * Licensed under the Educational Community License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.opensource.org/licenses/ecl2.php
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.kuali.rice.krad.uif.control;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.rice.krad.datadictionary.parse.BeanTag;
20 import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
21 import org.kuali.rice.krad.datadictionary.parse.BeanTags;
22 import org.kuali.rice.krad.uif.component.Component;
23 import org.kuali.rice.krad.uif.field.InputField;
24 import org.kuali.rice.krad.uif.view.View;
25
26 /**
27 * Represents a HTML TextArea control. Generally used for values that are very
28 * large (such as a description)
29 *
30 * @author Kuali Rice Team (rice.collab@kuali.org)
31 */
32 @BeanTags({@BeanTag(name = "textAreaControl-bean", parent = "Uif-TextAreaControl"),
33 @BeanTag(name = "smallTextAreaControl-bean", parent = "Uif-SmallTextAreaControl"),
34 @BeanTag(name = "mediumTextAreaControl-bean", parent = "Uif-MediumTextAreaControl"),
35 @BeanTag(name = "largeTextAreaControl-bean", parent = "Uif-LargeTextAreaControl")})
36 public class TextAreaControl extends ControlBase {
37 private static final long serialVersionUID = -4664558047325456844L;
38
39 private int rows;
40 private int cols;
41 private Integer maxLength;
42 private Integer minLength;
43
44 private boolean textExpand;
45 private String watermarkText = StringUtils.EMPTY;
46
47 public TextAreaControl() {
48 super();
49 }
50
51 /**
52 * The following actions are performed:
53 *
54 * <ul>
55 * <li>Defaults maxLength, minLength (if not set) to maxLength of parent field</li>
56 * </ul>
57 *
58 * @see org.kuali.rice.krad.uif.component.ComponentBase#performFinalize(org.kuali.rice.krad.uif.view.View,
59 * java.lang.Object, org.kuali.rice.krad.uif.component.Component)
60 */
61 @Override
62 public void performFinalize(View view, Object model, Component parent) {
63 super.performFinalize(view, model, parent);
64
65 if (parent instanceof InputField) {
66 InputField field = (InputField) parent;
67 if (getMaxLength() == null) {
68 setMaxLength(field.getMaxLength());
69 }
70
71 if (getMinLength() == null) {
72 setMinLength(field.getMinLength());
73 }
74 }
75 }
76
77 /**
78 * Number of rows the control should span (horizontal length)
79 *
80 * @return int number of rows
81 */
82 @BeanTagAttribute(name = "rows")
83 public int getRows() {
84 return this.rows;
85 }
86
87 /**
88 * Setter for the number of rows the control should span (horizontal length)
89 *
90 * @param rows
91 */
92 public void setRows(int rows) {
93 this.rows = rows;
94 }
95
96 /**
97 * Number of columns the control should span (vertical length)
98 *
99 * @return int number of columns
100 */
101 @BeanTagAttribute(name = "cols")
102 public int getCols() {
103 return this.cols;
104 }
105
106 /**
107 * Setter for the number of columns the control should span (vertical length)
108 *
109 * @param cols
110 */
111 public void setCols(int cols) {
112 this.cols = cols;
113 }
114
115 /**
116 * Maximum number of characters that can be inputted
117 *
118 * <p>If not set on control, max length of field will be used</p>
119 *
120 * @return int max number of characters
121 */
122 @BeanTagAttribute(name = "maxLength")
123 public Integer getMaxLength() {
124 return maxLength;
125 }
126
127 /**
128 * Setter for the max number of input characters
129 *
130 * @param maxLength
131 */
132 public void setMaxLength(Integer maxLength) {
133 this.maxLength = maxLength;
134 }
135
136 /**
137 * Minimum number of characters that can be inputted
138 *
139 * <p>If not set on control, min length of field will be used</p>
140 *
141 * @return int max number of characters
142 */
143 @BeanTagAttribute(name = "minLength")
144 public Integer getMinLength() {
145 return minLength;
146 }
147
148 /**
149 * Setter for the min number of input characters
150 *
151 * @param minLength
152 */
153 public void setMinLength(Integer minLength) {
154 this.minLength = minLength;
155 }
156
157 /**
158 * @return the watermarkText
159 */
160 @BeanTagAttribute(name = "watermarkText")
161 public String getWatermarkText() {
162 return this.watermarkText;
163 }
164
165 /**
166 * @param watermarkText the watermarkText to set
167 */
168 public void setWatermarkText(String watermarkText) {
169 //to avoid users from putting in the same value as the watermark adding some spaces here
170 //see watermark troubleshooting for more info
171 if (StringUtils.isNotEmpty(watermarkText)) {
172 watermarkText = watermarkText + " ";
173 }
174 this.watermarkText = watermarkText;
175 }
176
177 /**
178 * If set to true, this control will have a button which can be clicked to expand the text area through
179 * a popup window so the user has more space to type and see the data they are entering in this text field
180 *
181 * @return the textExpand
182 */
183 @BeanTagAttribute(name = "textExpand")
184 public boolean isTextExpand() {
185 return this.textExpand;
186 }
187
188 /**
189 * Setter for the text expand flag
190 *
191 * @param textExpand the textExpand to set
192 */
193 public void setTextExpand(boolean textExpand) {
194 this.textExpand = textExpand;
195 }
196 }