On Tue, Apr 08, 2008 at 06:41:20PM +0200, Vitaly Tsaplin wrote:
> Hi everyone,
>
> Lets say I am going to use a single integer value as a model object
> for the component CheckBoxMultipleChoice packing the selected choices
> somehow to this value as bits. Where can I do such a conversion? The
> method getConvertor is not called... the methods getConvertedInput and
> setConvertedInput are final...
>
> Vitaly
ListMultipleChoice/CheckBoxMultipleChoice require a model that returns a
Collection object, so your best bet is to create a model that wraps your
integer-returning model and presents the bits as a list of integers.
Here's some pseudocode that might help:
public class BitMapModel implements IModel {
private IModel targetModel;
public BitMapModel(IModel targetModel) {
this.targetModel = targetModel;
}
public Object getObject() {
List list = new ArrayList();
int bits = (Integer) targetModel.getObject();
for each bit in bits:
if bit==1:
add bit value to list
return list;
}
public void setObject(Object value) {
List list = (List) value;
int bits = 0;
for each bit in list:
bits |= bit;
}
targetModel.setObject(bits);
}
}
For example, if targetModel.getObject() returned the 5 (i.e. bits 0101),
this wrapper model would return the list [ 2, 0 ], and vice-versa for
setObject.
You'll also need a ChoiceRenderer to convert the bit values to
reasonable strings.
jk
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]