001/** 002 * Copyright 2005-2018 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.kuali.rice.krad.uif.control; 017 018import org.apache.commons.lang.StringUtils; 019import org.kuali.rice.krad.datadictionary.parse.BeanTag; 020import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute; 021import org.kuali.rice.krad.datadictionary.parse.BeanTags; 022import org.kuali.rice.krad.uif.component.Component; 023import org.kuali.rice.krad.uif.field.InputField; 024import org.kuali.rice.krad.uif.util.LifecycleElement; 025 026/** 027 * Represents a HTML TextArea control. Generally used for values that are very 028 * large (such as a description) 029 * 030 * @author Kuali Rice Team (rice.collab@kuali.org) 031 */ 032@BeanTags({@BeanTag(name = "textAreaControl", parent = "Uif-TextAreaControl"), 033 @BeanTag(name = "smallTextAreaControl", parent = "Uif-SmallTextAreaControl"), 034 @BeanTag(name = "mediumTextAreaControl", parent = "Uif-MediumTextAreaControl"), 035 @BeanTag(name = "largeTextAreaControl", parent = "Uif-LargeTextAreaControl")}) 036public class TextAreaControl extends ControlBase { 037 private static final long serialVersionUID = -4664558047325456844L; 038 039 private int rows; 040 private int cols; 041 private Integer maxLength; 042 private Integer minLength; 043 044 private boolean textExpand; 045 private String watermarkText = StringUtils.EMPTY; 046 047 public TextAreaControl() { 048 super(); 049 } 050 051 /** 052 * The following actions are performed: 053 * 054 * <ul> 055 * <li>Defaults maxLength, minLength (if not set) to maxLength of parent field</li> 056 * </ul> 057 * 058 * {@inheritDoc} 059 */ 060 @Override 061 public void performFinalize(Object model, LifecycleElement parent) { 062 super.performFinalize(model, parent); 063 064 if (parent instanceof InputField) { 065 InputField field = (InputField) parent; 066 if (getMaxLength() == null) { 067 setMaxLength(field.getMaxLength()); 068 } 069 070 if (getMinLength() == null) { 071 setMinLength(field.getMinLength()); 072 } 073 074 if (textExpand) { 075 field.setRenderInputAddonGroup(true); 076 } 077 } 078 } 079 080 /** 081 * Number of rows the control should span (horizontal length) 082 * 083 * @return number of rows 084 */ 085 @BeanTagAttribute 086 public int getRows() { 087 return this.rows; 088 } 089 090 /** 091 * Setter for the number of rows the control should span (horizontal length) 092 * 093 * @param rows 094 */ 095 public void setRows(int rows) { 096 this.rows = rows; 097 } 098 099 /** 100 * Number of columns the control should span (vertical length) 101 * 102 * @return number of columns 103 */ 104 @BeanTagAttribute 105 public int getCols() { 106 return this.cols; 107 } 108 109 /** 110 * Setter for the number of columns the control should span (vertical length) 111 * 112 * @param cols 113 */ 114 public void setCols(int cols) { 115 this.cols = cols; 116 } 117 118 /** 119 * Maximum number of characters that can be inputted 120 * 121 * <p>If not set on control, max length of field will be used</p> 122 * 123 * @return max number of characters 124 */ 125 @BeanTagAttribute 126 public Integer getMaxLength() { 127 return maxLength; 128 } 129 130 /** 131 * Setter for the max number of input characters 132 * 133 * @param maxLength 134 */ 135 public void setMaxLength(Integer maxLength) { 136 this.maxLength = maxLength; 137 } 138 139 /** 140 * Minimum number of characters that can be inputted 141 * 142 * <p>If not set on control, min length of field will be used</p> 143 * 144 * @return max number of characters 145 */ 146 @BeanTagAttribute 147 public Integer getMinLength() { 148 return minLength; 149 } 150 151 /** 152 * Setter for the min number of input characters 153 * 154 * @param minLength 155 */ 156 public void setMinLength(Integer minLength) { 157 this.minLength = minLength; 158 } 159 160 /** 161 * @return the watermarkText 162 */ 163 @BeanTagAttribute 164 public String getWatermarkText() { 165 return this.watermarkText; 166 } 167 168 /** 169 * @param watermarkText the watermarkText to set 170 */ 171 public void setWatermarkText(String watermarkText) { 172 //to avoid users from putting in the same value as the watermark adding some spaces here 173 //see watermark troubleshooting for more info 174 if (StringUtils.isNotEmpty(watermarkText)) { 175 watermarkText = watermarkText + " "; 176 } 177 this.watermarkText = watermarkText; 178 } 179 180 /** 181 * If set to true, this control will have a button which can be clicked to expand the text area through 182 * a popup window so the user has more space to type and see the data they are entering in this text field 183 * 184 * @return the textExpand 185 */ 186 @BeanTagAttribute 187 public boolean isTextExpand() { 188 return this.textExpand; 189 } 190 191 /** 192 * Setter for the text expand flag 193 * 194 * @param textExpand the textExpand to set 195 */ 196 public void setTextExpand(boolean textExpand) { 197 this.textExpand = textExpand; 198 } 199}