View Javadoc

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