You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@pivot.apache.org by treponema <tr...@orange.fr> on 2012/09/22 23:15:55 UTC

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...

Re: Is that a way to check or uncheck a checkbox using data binding?

Posted by Sandro Martini <sa...@gmail.com>.
Hi all,
I'm ready to look better at this, maybe to include in 2.0.3 (soon to
be released) ...

Objections from someone for including this ?
If not I'll create a jira issue (and post here the link) , but I need
the original author to attach there the code, so we are all happy (due
to ASF rules) :-) ... ok ?

Tell me.

Thanks,
Sandro


2012/11/8 treponema <tr...@orange.fr>:
> Hi,
> Sorry for this late answer.
> This is the more generic helper that I use on different windows :
>
> private static class CheckboxMapping<T> implements
> Button.ButtonDataBindMapping {
>         private final Set<Key<T>> set;
>         private final Checkbox cb;
>         private final Key<T> key;
>
>         public CheckboxMapping(Checkbox cb, Key<T> key, Set<Key<T>> set) {
>
>
>             this.cb = cb;
>             this.key = key;
>             this.set = set;
>
>         }
>
>         @Override
>         public Object toButtonData(Object value) {
>             if (value != null && ((List<Key<T>>) value).contains(key))
>                 cb.setSelected(true);
>             else
>                 cb.setSelected(false);
>
>             return cb.getButtonData();
>         }
>
>         @Override
>         public Object valueOf(Object buttonData) {
>             if (cb.isSelected())
>                 set.add(this.key);
>             return new ArrayList<Key<T>>(set);
>         }
>
>     }
>

Re: Is that a way to check or uncheck a checkbox using data binding?

Posted by Sandro Martini <sa...@gmail.com>.
Hi,
don't worry for the delay, I'm busy a lot like you .-) ...

Forwarding to dev list because now I'd like to hear what other Pivot
Developers say on this small addition (to me seems useful).
Could be for 2.1, or maybe even for 2.0.3 (we are near to a release
candicate, in next weeks).


This is our section in JIRA (Apache issue tracker):
https://issues.apache.org/jira/browse/PIVOT
you can sign (you have to register before, but it's fast) and add a
new issue (for example as improvement), and then you could attach a
sample code there, so then we could use it (these are rules at Apache
for us to accept code) ... and it's useful even for us, to not forget
things between releases :-) .
If you could do it, it would be great. If you need some help, sent to
me an email ...


Roger, Chris, and others, what do you think ?


Bye,
Sandro



2012/11/8 treponema <tr...@orange.fr>:
> Hi,
> Sorry for this late answer.
> This is the more generic helper that I use on different windows :
>
> private static class CheckboxMapping<T> implements
> Button.ButtonDataBindMapping {
>         private final Set<Key<T>> set;
>         private final Checkbox cb;
>         private final Key<T> key;
>
>         public CheckboxMapping(Checkbox cb, Key<T> key, Set<Key<T>> set) {
>
>
>             this.cb = cb;
>             this.key = key;
>             this.set = set;
>
>         }
>
>         @Override
>         public Object toButtonData(Object value) {
>             if (value != null && ((List<Key<T>>) value).contains(key))
>                 cb.setSelected(true);
>             else
>                 cb.setSelected(false);
>
>             return cb.getButtonData();
>         }
>
>         @Override
>         public Object valueOf(Object buttonData) {
>             if (cb.isSelected())
>                 set.add(this.key);
>             return new ArrayList<Key<T>>(set);
>         }
>
>     }
>
> I have to learn what a "JIRA issue" is, I am new to open source (I come from
> .Net). So I think nothing about this.
>
> Bye...
>
>
>
>> Message du 26/09/12 14:36
>> De : "Sandro Martini"
>> A : user@pivot.apache.org
>> Copie à :
>> Objet : Re: Is that a way to check or uncheck a checkbox using data
>> binding?
>
>>
>> Hi,
>>
>> I'm sorry but I don't have a better solution for this problem.
>>
>> Maybe for 2.1 we could think (if no better solution will come) to
>> write some helper classes like your (but maybe a little more generic)
>> but based on real use cases like this. A JIRA issue could be good too,
>> to not forget ...
>>
>> What do you think ?
>>
>> Bye,
>> Sandro
>>

Re: Is that a way to check or uncheck a checkbox using data binding?

Posted by Sandro Martini <sa...@gmail.com>.
Hi,
don't worry for the delay, I'm busy a lot like you .-) ...

Forwarding to dev list because now I'd like to hear what other Pivot
Developers say on this small addition (to me seems useful).
Could be for 2.1, or maybe even for 2.0.3 (we are near to a release
candicate, in next weeks).


This is our section in JIRA (Apache issue tracker):
https://issues.apache.org/jira/browse/PIVOT
you can sign (you have to register before, but it's fast) and add a
new issue (for example as improvement), and then you could attach a
sample code there, so then we could use it (these are rules at Apache
for us to accept code) ... and it's useful even for us, to not forget
things between releases :-) .
If you could do it, it would be great. If you need some help, sent to
me an email ...


Roger, Chris, and others, what do you think ?


Bye,
Sandro



2012/11/8 treponema <tr...@orange.fr>:
> Hi,
> Sorry for this late answer.
> This is the more generic helper that I use on different windows :
>
> private static class CheckboxMapping<T> implements
> Button.ButtonDataBindMapping {
>         private final Set<Key<T>> set;
>         private final Checkbox cb;
>         private final Key<T> key;
>
>         public CheckboxMapping(Checkbox cb, Key<T> key, Set<Key<T>> set) {
>
>
>             this.cb = cb;
>             this.key = key;
>             this.set = set;
>
>         }
>
>         @Override
>         public Object toButtonData(Object value) {
>             if (value != null && ((List<Key<T>>) value).contains(key))
>                 cb.setSelected(true);
>             else
>                 cb.setSelected(false);
>
>             return cb.getButtonData();
>         }
>
>         @Override
>         public Object valueOf(Object buttonData) {
>             if (cb.isSelected())
>                 set.add(this.key);
>             return new ArrayList<Key<T>>(set);
>         }
>
>     }
>
> I have to learn what a "JIRA issue" is, I am new to open source (I come from
> .Net). So I think nothing about this.
>
> Bye...
>
>
>
>> Message du 26/09/12 14:36
>> De : "Sandro Martini"
>> A : user@pivot.apache.org
>> Copie à :
>> Objet : Re: Is that a way to check or uncheck a checkbox using data
>> binding?
>
>>
>> Hi,
>>
>> I'm sorry but I don't have a better solution for this problem.
>>
>> Maybe for 2.1 we could think (if no better solution will come) to
>> write some helper classes like your (but maybe a little more generic)
>> but based on real use cases like this. A JIRA issue could be good too,
>> to not forget ...
>>
>> What do you think ?
>>
>> Bye,
>> Sandro
>>

Re: Is that a way to check or uncheck a checkbox using data binding?

Posted by treponema <tr...@orange.fr>.
Hi,
Sorry for this late answer.
This is the more generic helper that I use on different windows :
private static class CheckboxMapping implements Button.ButtonDataBindMapping {
        private final Set> set; 
        private final Checkbox cb;        
        private final Key key;
        
        public CheckboxMapping(Checkbox cb, Key key, Set> set) {
            this.cb = cb;
            this.key = key;
            this.set = set;
        }

        @Override
        public Object toButtonData(Object value) {
            if (value != null && ((List>) value).contains(key))
                cb.setSelected(true);
            else 
                cb.setSelected(false);
            return cb.getButtonData();
        }

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

I have to learn what a "JIRA issue" is, I am new to open source (I come from .Net). So I think nothing about this.

Bye...

 

> Message du 26/09/12 14:36
> De : "Sandro Martini" 
> A : user@pivot.apache.org
> Copie à : 
> Objet : Re: Is that a way to check or uncheck a checkbox using data binding?
> 
> Hi,
> 
> I'm sorry but I don't have a better solution for this problem.
> 
> Maybe for 2.1 we could think (if no better solution will come) to
> write some helper classes like your (but maybe a little more generic)
> but based on real use cases like this. A JIRA issue could be good too,
> to not forget ...
> 
> What do you think ?
> 
> Bye,
> Sandro
>

Re: Is that a way to check or uncheck a checkbox using data binding?

Posted by Sandro Martini <sa...@gmail.com>.
Hi,

I'm sorry but I don't have a better solution for this problem.

Maybe for 2.1 we could think (if no better solution will come) to
write some helper classes like your (but maybe a little more generic)
but based on real use cases like this. A JIRA issue could be good too,
to not forget ...

What do you think ?

Bye,
Sandro

RE: Is that a way to check or uncheck a checkbox using data binding?

Posted by treponema <tr...@orange.fr>.
Hi again,

I realized that parts of the code were removed, so I post this message again, this time using HTML.


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...





RE: Is that a way to check or uncheck a checkbox using data binding?

Posted by treponema <tr...@orange.fr>.
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 : 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...
>

RE: Is that a way to check or uncheck a checkbox using data binding?

Posted by "Roger L. Whitcomb" <Ro...@actian.com>.
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...

Re: Is that a way to check or uncheck a checkbox using data binding?

Posted by Sandro Martini <sa...@gmail.com>.
Hi,
(just to be sure) have you looked at this:
http://pivot.apache.org/tutorials/data-binding.html
and
http://pivot.apache.org/tutorials/property-binding.html
?

Ok, there isn't a checkbox example in both ... I'll try to add a
sample for this later.
Anyway, for example, try to add a boolean property in the bean backing the form.

And look at Button method:
    public State getState() {
to get the state (checked/unchecked) of the button ...

Sorry but at the moment I haven't more time ... tell me something.


Bye