Bind h:selectBooleanCheckbox value to int/Integer instead of boolean/Boolean

The <h:selectBooleanCheckbox> should, as its name say, be bound to a boolean or Boolean property. Nothing else. That it allows a converter attribute is actually a bug in the spec. It should never have allowed it.

The problem is more in your model, why would you use an int to represent a boolean state? Change your model to let it be a fullworthy boolean.

If changing the model isn't an option for some reason (a 3rd party API, a stupid architect, or stupid business restrictions, etc), then wrap the model getter/setter in the backing bean like follows

public boolean isChecked() {
    return someModel.getSomeInt() != 0;
}

public void setChecked(boolean checked) {
    someModel.setSomeInt(checked ? 1 : 0);
}

and use it instead as <h:selectBooleanCheckbox value="#{bean.checked}" />.


just to say MySQL doesn't have boolean as field type choice, and it could be an example for this need.