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 Wed, 26 Sep 2012 08:30:39 GMT
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...





Mime
View raw message