1 /**
2 * Copyright 2005-2014 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.util.LifecycleElement;
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 * {@inheritDoc}
59 */
60 @Override
61 public void performFinalize(Object model, LifecycleElement parent) {
62 super.performFinalize(model, parent);
63
64 if (parent instanceof InputField) {
65 InputField field = (InputField) parent;
66 if (getMaxLength() == null) {
67 setMaxLength(field.getMaxLength());
68 }
69
70 if (getMinLength() == null) {
71 setMinLength(field.getMinLength());
72 }
73
74 if (textExpand) {
75 field.setRenderInputAddonGroup(true);
76 }
77 }
78 }
79
80 /**
81 * Number of rows the control should span (horizontal length)
82 *
83 * @return number of rows
84 */
85 @BeanTagAttribute(name = "rows")
86 public int getRows() {
87 return this.rows;
88 }
89
90 /**
91 * Setter for the number of rows the control should span (horizontal length)
92 *
93 * @param rows
94 */
95 public void setRows(int rows) {
96 this.rows = rows;
97 }
98
99 /**
100 * Number of columns the control should span (vertical length)
101 *
102 * @return number of columns
103 */
104 @BeanTagAttribute(name = "cols")
105 public int getCols() {
106 return this.cols;
107 }
108
109 /**
110 * Setter for the number of columns the control should span (vertical length)
111 *
112 * @param cols
113 */
114 public void setCols(int cols) {
115 this.cols = cols;
116 }
117
118 /**
119 * Maximum number of characters that can be inputted
120 *
121 * <p>If not set on control, max length of field will be used</p>
122 *
123 * @return max number of characters
124 */
125 @BeanTagAttribute(name = "maxLength")
126 public Integer getMaxLength() {
127 return maxLength;
128 }
129
130 /**
131 * Setter for the max number of input characters
132 *
133 * @param maxLength
134 */
135 public void setMaxLength(Integer maxLength) {
136 this.maxLength = maxLength;
137 }
138
139 /**
140 * Minimum number of characters that can be inputted
141 *
142 * <p>If not set on control, min length of field will be used</p>
143 *
144 * @return max number of characters
145 */
146 @BeanTagAttribute(name = "minLength")
147 public Integer getMinLength() {
148 return minLength;
149 }
150
151 /**
152 * Setter for the min number of input characters
153 *
154 * @param minLength
155 */
156 public void setMinLength(Integer minLength) {
157 this.minLength = minLength;
158 }
159
160 /**
161 * @return the watermarkText
162 */
163 @BeanTagAttribute(name = "watermarkText")
164 public String getWatermarkText() {
165 return this.watermarkText;
166 }
167
168 /**
169 * @param watermarkText the watermarkText to set
170 */
171 public void setWatermarkText(String watermarkText) {
172 //to avoid users from putting in the same value as the watermark adding some spaces here
173 //see watermark troubleshooting for more info
174 if (StringUtils.isNotEmpty(watermarkText)) {
175 watermarkText = watermarkText + " ";
176 }
177 this.watermarkText = watermarkText;
178 }
179
180 /**
181 * If set to true, this control will have a button which can be clicked to expand the text area through
182 * a popup window so the user has more space to type and see the data they are entering in this text field
183 *
184 * @return the textExpand
185 */
186 @BeanTagAttribute(name = "textExpand")
187 public boolean isTextExpand() {
188 return this.textExpand;
189 }
190
191 /**
192 * Setter for the text expand flag
193 *
194 * @param textExpand the textExpand to set
195 */
196 public void setTextExpand(boolean textExpand) {
197 this.textExpand = textExpand;
198 }
199 }