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 import org.kuali.rice.krad.uif.widget.DatePicker;
26
27 /**
28 * Represents a HTML Text control, generally rendered as a input field of type
29 * 'text'. This can display and receive a single value
30 *
31 * @author Kuali Rice Team (rice.collab@kuali.org)
32 */
33 @BeanTags({@BeanTag(name = "textControl-bean", parent = "Uif-TextControl"),
34 @BeanTag(name = "smallTextControl-bean", parent = "Uif-SmallTextControl"),
35 @BeanTag(name = "mediumTextControl-bean", parent = "Uif-MediumTextControl"),
36 @BeanTag(name = "largeTextControl-bean", parent = "Uif-LargeTextControl"),
37 @BeanTag(name = "currencyTextControl-bean", parent = "Uif-CurrencyTextControl"),
38 @BeanTag(name = "dateControl-bean", parent = "Uif-DateControl")})
39 public class TextControlBase extends ControlBase implements TextControl, SizedControl {
40 private static final long serialVersionUID = -8267606288443759880L;
41
42 private int size;
43 private Integer maxLength;
44 private Integer minLength;
45
46 private DatePicker datePicker;
47 private String watermarkText = StringUtils.EMPTY;
48 private boolean textExpand;
49
50 public TextControlBase() {
51 super();
52 }
53
54 /**
55 * The following actions are performed:
56 *
57 * <ul>
58 * <li>Defaults maxLength, minLength (if not set) to maxLength of parent field</li>
59 * </ul>
60 *
61 * {@inheritDoc}
62 */
63 @Override
64 public void performFinalize(Object model, LifecycleElement parent) {
65 super.performFinalize(model, parent);
66
67 if (parent instanceof InputField) {
68 InputField field = (InputField) parent;
69 if (getMaxLength() == null) {
70 setMaxLength(field.getMaxLength());
71 }
72
73 if (getMinLength() == null) {
74 setMinLength(field.getMinLength());
75 }
76
77 if (textExpand) {
78 field.setRenderInputAddonGroup(true);
79 }
80 }
81 }
82
83 /**
84 * @see org.kuali.rice.krad.uif.control.SizedControl#getSize()
85 */
86 @BeanTagAttribute(name = "size")
87 public int getSize() {
88 return this.size;
89 }
90
91 /**
92 * @see org.kuali.rice.krad.uif.control.SizedControl#setSize(int)
93 */
94 public void setSize(int size) {
95 this.size = size;
96 }
97
98 /**
99 * Maximum number of characters that can be inputted
100 *
101 * <p>If not set on control, max length of field will be used</p>
102 *
103 * @return max number of characters
104 */
105 @BeanTagAttribute(name = "maxLength")
106 public Integer getMaxLength() {
107 return maxLength;
108 }
109
110 /**
111 * Setter for the max number of input characters
112 *
113 * @param maxLength
114 */
115 public void setMaxLength(Integer maxLength) {
116 this.maxLength = maxLength;
117 }
118
119 /**
120 * Minimum number of characters that can be inputted
121 *
122 * <p>If not set on control, min length of field will be used</p>
123 *
124 * @return max number of characters
125 */
126 @BeanTagAttribute(name = "minLength")
127 public Integer getMinLength() {
128 return minLength;
129 }
130
131 /**
132 * Setter for the min number of input characters
133 *
134 * @param minLength
135 */
136 public void setMinLength(Integer minLength) {
137 this.minLength = minLength;
138 }
139
140 /**
141 * Renders a calendar that can be used to select a date value for the text
142 * control. The <code>Calendar</code> instance contains configuration such
143 * as the date format string
144 *
145 * @return Calendar
146 */
147 @BeanTagAttribute(name = "datePicker", type = BeanTagAttribute.AttributeType.SINGLEBEAN)
148 public DatePicker getDatePicker() {
149 return this.datePicker;
150 }
151
152 /**
153 * Setter for the date picker
154 *
155 * @param datePicker
156 */
157 public void setDatePicker(DatePicker datePicker) {
158 this.datePicker = datePicker;
159 }
160
161 /**
162 * Gets the watermark text for this TextControl.
163 *
164 * <p>
165 * A watermark typically appears as light gray text within the text input element whenever the
166 * element is empty and does not have focus. This provides a hint to the user as to what the input
167 * is used for, or the type of input that is required.
168 * </p>
169 *
170 * @return the watermarkText
171 */
172 @BeanTagAttribute(name = "watermarkText")
173 public String getWatermarkText() {
174 return this.watermarkText;
175 }
176
177 /**
178 * Sets the watermark text for this TextControl
179 *
180 * @param watermarkText the watermarkText to set
181 */
182 public void setWatermarkText(String watermarkText) {
183 //to avoid users from putting in the same value as the watermark adding some spaces here
184 //see watermark troubleshooting for more info
185 if (StringUtils.isNotEmpty(watermarkText)) {
186 watermarkText = watermarkText + " ";
187 }
188 this.watermarkText = watermarkText;
189 }
190
191 /**
192 * If set to true, this control will have a button which can be clicked to expand the text area through
193 * a popup window so the user has more space to type and see the data they are entering in this text field.
194 *
195 * @return the textExpand
196 */
197 @BeanTagAttribute(name = "textExpand")
198 public boolean isTextExpand() {
199 return this.textExpand;
200 }
201
202 /**
203 * Sets whether this control will have a button to expand the text area through a popup window.
204 *
205 * @param textExpand the textExpand to set
206 */
207 public void setTextExpand(boolean textExpand) {
208 this.textExpand = textExpand;
209 }
210
211 }