com.evasion.common.component.TextItem 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.HtmlInputText;
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 TextItem 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() {
HtmlInputText input = new HtmlInputText();
LengthValidator validator = new LengthValidator();
if (getMaxLenght() != null) {
input.setSize(getMaxLenght());
input.setMaxlength(getMaxLenght());
validator.setMaximum(getMaxLenght());
}
validator.setMinimum(getMinLenght());
input.addValidator(validator);
return input;
}
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);
}
}