问题
In an XPage I have a CheckBox control bound to a property of a bean (called product). If I make that property a boolean like so..
private boolean selected = true;
public boolean isSelected() {
return selected;
};
public void setSelected(boolean selected) {
this.selected = selected;
};
and bind the checkbox using EL as #{product.selected)
then the page initially opens fine but hangs on a partial refresh, however I can't see any errors in the logs.
If I add another wrapper getter/setter in the bean to return a text version like so:
public String getSelectedTxt() {
return String.valueOf(selected);
}
public void setSelectedTxt(String selectedTxt) {
selected = Boolean.parseBoolean(selectedTxt);
}
then bind the checkbox to #{product.selectedTxt}
and make the uncheckedValue="false"
and checkedValue="true"
. It works!
In version 9 it works straight against the boolean version without the need to convert to text.
So the question is does this sound like a bug in 8.5.3 with mapping checkbox controls to boolean values (has anyone done that before?), or am I approaching this the wrong way?
回答1:
Checkboxes are one of a range of options for displaying the contents of Notes fields of type "Keywords". Keywords are Text fields that have a finite set of values. While you may think of a Checkbox as being a Boolean control that was not their original purpose or intent. So I would not look upon the 8.5.3 implementation as a bug. If the 9.0 behavior has changed to support boolean values then that is good news.
来源:https://stackoverflow.com/questions/15546635/binding-a-checkbox-control-to-a-bean-in-xpages