Thanks John,

   It was the idea that came to my mind first. The question is where I
can create such a wrapper? I need to have it compatible with
CompountPropertyModel... That's the sticking point. Since I cannot
store an array in my mysql database anyway I am going to implement a
subclass of CheckBoxMultipleChoice and use it most of the time.
Everything else like IChoiceRenderer and so on I have already
implemented. The only problem is where to put the conversion code. Any
ideas?

On Tue, Apr 8, 2008 at 7:36 PM, John Krasnay <[EMAIL PROTECTED]> wrote:
>
> 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]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to