pivot-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From treponema <trepon...@orange.fr>
Subject RE: Is that a way to check or uncheck a checkbox using data binding?
Date Tue, 25 Sep 2012 10:46:31 GMT
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;

public Object toButtonData(Object value) {
if (((List>) value).contains(key))
return cb.getButtonData();

public Object valueOf(Object buttonData) {
if (cb.isSelected())
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.

> Message du 24/09/12 19:00
> De : "Roger L. Whitcomb" 
> A : user@pivot.apache.org, "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:treponema@orange.fr] 
> Sent: Saturday, September 22, 2012 2:16 PM
> To: user@pivot.apache.org
> 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...

View raw message