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