View Javadoc

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.uif.field.InputField;
20  import org.kuali.rice.krad.uif.view.View;
21  import org.kuali.rice.krad.uif.component.Component;
22  
23  /**
24   * Represents a HTML TextArea control. Generally used for values that are very
25   * large (such as a description)
26   *
27   * @author Kuali Rice Team (rice.collab@kuali.org)
28   */
29  public class TextAreaControl extends ControlBase {
30      private static final long serialVersionUID = -4664558047325456844L;
31  
32      private int rows;
33      private int cols;
34      private Integer maxLength;
35      private Integer minLength;
36  
37      private boolean textExpand;
38      private String watermarkText = StringUtils.EMPTY;
39  
40      public TextAreaControl() {
41          super();
42      }
43  
44      /**
45       * The following actions are performed:
46       *
47       * <ul>
48       * <li>Defaults maxLength, minLength (if not set) to maxLength of parent field</li>
49       * </ul>
50       *
51       * @see org.kuali.rice.krad.uif.component.ComponentBase#performFinalize(org.kuali.rice.krad.uif.view.View,
52       *      java.lang.Object, org.kuali.rice.krad.uif.component.Component)
53       */
54      @Override
55      public void performFinalize(View view, Object model, Component parent) {
56          super.performFinalize(view, model, parent);
57  
58          if (parent instanceof InputField) {
59              InputField field = (InputField) parent;
60              if (getMaxLength() == null) {
61                  setMaxLength(field.getMaxLength());
62              }
63  
64              if (getMinLength() == null) {
65                  setMinLength(field.getMinLength());
66              }
67          }
68      }
69  
70      /**
71       * Number of rows the control should span (horizontal length)
72       *
73       * @return int number of rows
74       */
75      public int getRows() {
76          return this.rows;
77      }
78  
79      public void setRows(int rows) {
80          this.rows = rows;
81      }
82  
83      /**
84       * Number of columns the control should span (vertical length)
85       *
86       * @return int number of columns
87       */
88      public int getCols() {
89          return this.cols;
90      }
91  
92      public void setCols(int cols) {
93          this.cols = cols;
94      }
95  
96      /**
97       * Maximum number of characters that can be inputted
98       *
99       * <p>If not set on control, max length of field will be used</p>
100      *
101      * @return int max number of characters
102      */
103     public Integer getMaxLength() {
104         return maxLength;
105     }
106 
107     /**
108      * Setter for the max number of input characters
109      *
110      * @param maxLength
111      */
112     public void setMaxLength(Integer maxLength) {
113         this.maxLength = maxLength;
114     }
115 
116     /**
117      * Minimum number of characters that can be inputted
118      *
119      * <p>If not set on control, min length of field will be used</p>
120      *
121      * @return int max number of characters
122      */
123     public Integer getMinLength() {
124         return minLength;
125     }
126 
127     /**
128      * Setter for the min number of input characters
129      *
130      * @param minLength
131      */
132     public void setMinLength(Integer minLength) {
133         this.minLength = minLength;
134     }
135 
136     /**
137      * @return the watermarkText
138      */
139     public String getWatermarkText() {
140         return this.watermarkText;
141     }
142 
143     /**
144      * @param watermarkText the watermarkText to set
145      */
146     public void setWatermarkText(String watermarkText) {
147         //to avoid users from putting in the same value as the watermark adding some spaces here
148         //see watermark troubleshooting for more info
149         if (StringUtils.isNotEmpty(watermarkText)) {
150             watermarkText = watermarkText + "   ";
151         }
152         this.watermarkText = watermarkText;
153     }
154 
155     /**
156      * If set to true, this control will have a button which can be clicked to expand the text area through
157      * a popup window so the user has more space to type and see the data they are entering in this text field
158      *
159      * @return the textExpand
160      */
161     public boolean isTextExpand() {
162         return this.textExpand;
163     }
164 
165     /**
166      * Setter for the text expand flag
167      *
168      * @param textExpand the textExpand to set
169      */
170     public void setTextExpand(boolean textExpand) {
171         this.textExpand = textExpand;
172     }
173 
174 
175 }