org.butterfaces.component.html.HtmlCheckBox Maven / Gradle / Ivy
package org.butterfaces.component.html;
import org.butterfaces.component.html.feature.AutoFocus;
import org.butterfaces.component.html.feature.Label;
import org.butterfaces.component.html.feature.Readonly;
import org.butterfaces.component.html.feature.Tooltip;
import javax.el.ValueExpression;
import javax.faces.application.ResourceDependencies;
import javax.faces.application.ResourceDependency;
import javax.faces.component.FacesComponent;
import javax.faces.component.html.HtmlSelectBooleanCheckbox;
import java.util.Collections;
import java.util.List;
@ResourceDependencies({
@ResourceDependency(library = "butterfaces-dist-css", name = "butterfaces-default.css", target = "head"),
@ResourceDependency(library = "butterfaces-dist-css", name = "butterfaces-checkbox.css", target = "head"),
@ResourceDependency(library = "butterfaces-dist-css", name = "dist-butterfaces-bootstrap.css", target = "head"),
@ResourceDependency(library = "butterfaces-dist-bundle-dev-js", name = "butterfaces-third-party-jquery.js", target = "head"),
@ResourceDependency(library = "butterfaces-dist-bundle-dev-js", name = "butterfaces-third-party-bootstrap.js", target = "head")
})
@FacesComponent(HtmlCheckBox.COMPONENT_TYPE)
public class HtmlCheckBox extends HtmlSelectBooleanCheckbox implements HtmlInputComponent, AutoFocus, Tooltip, Label, Readonly {
public static final String COMPONENT_TYPE = "org.butterfaces.component.checkBox";
public static final String COMPONENT_FAMILY = "org.butterfaces.component.family";
public static final String RENDERER_TYPE = "org.butterfaces.component.renderkit.html_basic.CheckBoxRenderer";
protected static final String PROPERTY_HIDE_LABEL = "hideLabel";
protected static final String PROPERTY_DESCRIPTION = "description";
protected static final String PROPERTY_HTML5_AUTO_FOCUS = "autoFocus";
protected static final String PROPERTY_SWITCH = "switch";
protected static final String PROPERTY_VALIDATION_ERROR_PLACEMENT = "validationErrorPlacement";
public HtmlCheckBox() {
super();
this.setRendererType(RENDERER_TYPE);
}
@Override
public List getSupportedFacets() {
return Collections.emptyList();
}
@Override
public String getFamily() {
return COMPONENT_FAMILY;
}
@Override
public boolean isAutoFocus() {
final Object eval = this.getStateHelper().eval(PROPERTY_HTML5_AUTO_FOCUS);
return eval == null ? false : (Boolean) eval;
}
@Override
public void setAutoFocus(final boolean autoFocus) {
this.updateStateHelper(PROPERTY_HTML5_AUTO_FOCUS, autoFocus);
}
@Override
public boolean isHideLabel() {
final Object eval = this.getStateHelper().eval(PROPERTY_HIDE_LABEL);
return eval == null ? false : (Boolean) eval;
}
public void setHideLabel(final boolean hideLabel) {
this.updateStateHelper(PROPERTY_HIDE_LABEL, hideLabel);
}
public boolean isSwitch() {
final Object eval = this.getStateHelper().eval(PROPERTY_SWITCH);
return eval == null ? false : (Boolean) eval;
}
public void setSwitch(final boolean switching) {
this.updateStateHelper(PROPERTY_SWITCH, switching);
}
public String getDescription() {
return (String) this.getStateHelper().eval(PROPERTY_DESCRIPTION);
}
public void setDescription(final String description) {
this.updateStateHelper(PROPERTY_DESCRIPTION, description);
}
@Override
public String getValidationErrorPlacement() {
return (String) this.getStateHelper().eval(PROPERTY_VALIDATION_ERROR_PLACEMENT, "");
}
public void setValidationErrorPlacement(final String validationErrorPlacement) {
this.updateStateHelper(PROPERTY_VALIDATION_ERROR_PLACEMENT, validationErrorPlacement);
}
private void updateStateHelper(final String propertyName, final Object value) {
this.getStateHelper().put(propertyName, value);
final ValueExpression ve = this.getValueExpression(propertyName);
if (ve != null) {
ve.setValue(this.getFacesContext().getELContext(), value);
}
}
}