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.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 password text control, rendered as a input field of type
31   * 'password'. This can receive and display a mask for a single value.
32   *
33   * @author Kuali Rice Team (rice.collab@kuali.org)
34   */
35  @BeanTag(name = "passwordControl-bean", parent = "Uif-PasswordControl")
36  public class PasswordControl extends ControlBase implements SizedControl {
37      private static final long serialVersionUID = -8267606288443759880L;
38  
39      private int size;
40      private Integer maxLength;
41      private Integer minLength;
42  
43      private String watermarkText = StringUtils.EMPTY;
44  
45      public PasswordControl() {
46          super();
47      }
48  
49      /**
50       * The following actions are performed:
51       *
52       * <ul>
53       * <li>Defaults maxLength, minLength (if not set) to maxLength of parent field</li>
54       * </ul>
55       *
56       * @see org.kuali.rice.krad.uif.component.ComponentBase#performFinalize(org.kuali.rice.krad.uif.view.View,
57       *      Object, org.kuali.rice.krad.uif.component.Component)
58       */
59      @Override
60      public void performFinalize(View view, Object model, Component parent) {
61          super.performFinalize(view, model, parent);
62  
63          if (parent instanceof InputField) {
64              InputField field = (InputField) parent;
65              if (getMaxLength() == null) {
66                  setMaxLength(field.getMaxLength());
67              }
68  
69              if (getMinLength() == null) {
70                  setMinLength(field.getMinLength());
71              }
72          }
73      }
74  
75      /**
76       * @see SizedControl#getSize()
77       */
78      @BeanTagAttribute(name = "size")
79      public int getSize() {
80          return this.size;
81      }
82  
83      /**
84       * @see SizedControl#setSize(int)
85       */
86      public void setSize(int size) {
87          this.size = size;
88      }
89  
90      /**
91       * Maximum number of characters that can be inputted
92       *
93       * <p>If not set on control, max length of field will be used</p>
94       *
95       * @return max number of characters
96       */
97      @BeanTagAttribute(name = "maxLength")
98      public Integer getMaxLength() {
99          return maxLength;
100     }
101 
102     /**
103      * Setter for the max number of input characters
104      *
105      * @param maxLength
106      */
107     public void setMaxLength(Integer maxLength) {
108         this.maxLength = maxLength;
109     }
110 
111     /**
112      * Minimum number of characters that can be inputted
113      *
114      * <p>If not set on control, min length of field will be used</p>
115      *
116      * @return max number of characters
117      */
118     @BeanTagAttribute(name = "minLength")
119     public Integer getMinLength() {
120         return minLength;
121     }
122 
123     /**
124      * Setter for the min number of input characters
125      *
126      * @param minLength
127      */
128     public void setMinLength(Integer minLength) {
129         this.minLength = minLength;
130     }
131 
132     /**
133      * Gets the watermark text for this PasswordControl.
134      *
135      * <p>
136      * A watermark typically appears as light gray text within the Password input element whenever the
137      * element is empty and does not have focus. This provides a hint to the user as to what the input
138      * is used for, or the type of input that is required.
139      * </p>
140      *
141      * @return the watermarkText
142      */
143     @BeanTagAttribute(name = "watermarkText")
144     public String getWatermarkText() {
145         return this.watermarkText;
146     }
147 
148     /**
149      * Sets the watermark text for this PasswordControl
150      *
151      * @param watermarkText the watermarkText to set
152      */
153     public void setWatermarkText(String watermarkText) {
154         //to avoid users from putting in the same value as the watermark adding some spaces here
155         //see watermark troubleshooting for more info
156         if (StringUtils.isNotEmpty(watermarkText)) {
157             watermarkText = watermarkText + "   ";
158         }
159 
160         this.watermarkText = watermarkText;
161     }
162 
163     /**
164      * @see org.kuali.rice.krad.uif.component.ComponentBase#copy()
165      */
166     @Override
167     protected <T> void copyProperties(T component) {
168         super.copyProperties(component);
169         PasswordControl passwordControlCopy = (PasswordControl) component;
170         passwordControlCopy.setSize(this.size);
171         passwordControlCopy.setMaxLength(this.maxLength);
172         passwordControlCopy.setMinLength(this.minLength);
173         passwordControlCopy.setWatermarkText(this.watermarkText);
174     }
175 }