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