Hi,
Sandro and Roger, I thank you for your answers. 
I think that I have oversimplified my question. Actually, my bean has a list of 
keys, in my form there is one checkbox for each value that could be in the 
list. I would like to check all the checkboxes which keys are in the list and 
get the modifications back to my bean via the context. I have written this 
class :
private static class CheckboxMapping implements Button.ButtonDataBindMapping {
private static final Set> typesPlat = new HashSet>();
private final Checkbox cb; 
private final Key key;

public CheckboxMapping(Checkbox cb, Key key) {
this.cb = cb;
this.key = key;
}

@Override
public Object toButtonData(Object value) {
if (((List>) value).contains(key))
cb.setSelected(true);
return cb.getButtonData();
}

@Override
public Object valueOf(Object buttonData) {
if (cb.isSelected())
typesPlat.add(this.key);
return new ArrayList>(typesPlat);
}

} 
I set the setButtonDataBindMapping with a new instance of this class with the 
checkbox and the key as parameters, then I set the setButtonDataKey with the 
name of the bean list of keys. 
It is ugly, but it works. If there is a smarter solution, I would be glad to 
read it.
Bye...






> Message du 24/09/12 19:00
> De : "Roger L. Whitcomb" 
> A : [email protected], "treponema" 
> Copie à : 
> Objet : RE: Is that a way to check or uncheck a checkbox using data binding?
> 
> You need to use the "setSelectedKey()" and "setSelectedBindType()". This sets 
> the field name that is used to either load or store the selected state (a 
> Boolean) of the checkbox. The button data is the text of the checkbox, and 
> that's what "setButtonDataKey()" refers to. Alternatively, you could use 
> "setStateKey()" and "setStateBindType()" but this would require bean methods 
> that accept/return Button.State (this could be used for a tri-state checkbox).
> 
> HTH,
> ~Roger Whitcomb
> 
> -----Original Message-----
> From: treponema [mailto:[email protected]] 
> Sent: Saturday, September 22, 2012 2:16 PM
> To: [email protected]
> Subject: Is that a way to check or uncheck a checkbox using data binding?
> 
> Hi,
> I have a bean with a boolean property. I would like to use data binding to 
> check or uncheck a checkbox regarding this property and get the new state 
> back using the context's load an store methods. The only thing I managed to 
> do, is to change the ButtonData (the text near the checkbox) using 
> setButtonDataKey or by implementing Button.ButtonDataBindMapping. Can someone 
> give me a sample or some explanations ?
> Thanks...
>

Reply via email to