"bind h:selectbooleancheckbox value to int/integer instead of boolean/boolean" Code Answer

3

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}" />.

By Yassin Hajaj on September 15 2022

Answers related to “bind h:selectbooleancheckbox value to int/integer instead of boolean/boolean”

Only authorized users can answer the Search term. Please sign in first, or register a free account.