com.evasion.common.component.SecretItem Maven / Gradle / Ivy
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.evasion.common.component;
import javax.faces.application.ResourceDependencies;
import javax.faces.application.ResourceDependency;
import javax.faces.component.FacesComponent;
import javax.faces.component.UIInput;
import javax.faces.component.html.HtmlInputSecret;
import javax.faces.validator.LengthValidator;
/**
*
* @author glon-56610
*/
@FacesComponent(value = "com.evasion.common.component.TextItem")
@ResourceDependencies({
@ResourceDependency(name = "component/core.css", target = "head"),
@ResourceDependency(name = "component/theme.css", target = "head")
})
public class SecretItem extends FormItem {
private enum PropertyKeys {
minLength,
maxLength;
String toString;
PropertyKeys(String toString) {
this.toString = toString;
}
PropertyKeys() {
}
@Override
public String toString() {
return ((toString != null) ? toString : super.toString());
}
}
@Override
public UIInput createInput() {
HtmlInputSecret inputUser = new HtmlInputSecret();
LengthValidator validator = new LengthValidator();
if (getMaxLenght() != null) {
inputUser.setSize(getMaxLenght());
inputUser.setMaxlength(getMaxLenght());
validator.setMaximum(getMaxLenght());
}
validator.setMinimum(getMinLenght());
inputUser.addValidator(validator);
return inputUser;
}
public void setMaxLenght(Integer size) {
getStateHelper().put(PropertyKeys.maxLength, size);
handleAttribute(PropertyKeys.maxLength.toString(), size);
}
public Integer getMaxLenght() {
return (Integer) getStateHelper().eval(PropertyKeys.maxLength, null);
}
public void setMinLenght(Integer size) {
getStateHelper().put(PropertyKeys.minLength, size);
handleAttribute(PropertyKeys.minLength.toString(), size);
}
public Integer getMinLenght() {
return (Integer) getStateHelper().eval(PropertyKeys.minLength, 0);
}
}