How about something like this:
public class CommaSeparatedToStringListModel implements IModel<List<String>>
{
    private final IModel<String> csvModel;

    public CommaSeparatedToStringListModel(final IModel<String> csvModel)
    {
        this.csvModel = csvModel;
    }

    public List<String> getObject()
    {
        return new
ArrayList<String>(Arrays.asList(csvModel.getObject().split(",")));
    }

    public void setObject(final List<String> strings)
    {
        StringBuilder builder = new StringBuilder();
        for (String string : strings)
        {
            if(builder.length() > 0)
            {
                builder.append(",");
            }
            builder.append(string);
        }
        csvModel.setObject(builder.toString());
    }

    public void detach()
    {
        csvModel.detach();
    }
}

On Thu, Dec 4, 2008 at 10:00 AM, pixologe <[EMAIL PROTECTED]> wrote:

>
> Thanks for the reply...
> that's exactly what I just tried, until I realized that this will not work
> for writing the selected options back to the my domain object... at least I
> think so:
> I can teach the model to accept either String and List in setObject,
> however
> there's no way of letting it return different types in getObject, depending
> on the requestor...
> Or am I just completely on the wrong track and missing something quite
> obvious? Probably ;-)
>
>
> jwcarman wrote:
> >
> > I would just create a model that wraps the property model and does the
> > conversion.
> >
> > On Thu, Dec 4, 2008 at 9:12 AM, pixologe <[EMAIL PROTECTED]>
> wrote:
> >
> >>
> >> Hi everybody,
> >>
> >> I wonder if there is an elegant way to feed a ListMultipleChoice
> >> component
> >> with a comma separated string (using a PropertyModel)
> >>
> >> e.g. with the following property to be accessed by PropertyModel:
> >>
> >> public String getMySelectedOptions() {
> >> return "optionA,optionC";
> >> }
> >>
> >>
> >> ...something like this:
> >>
> >> List<String> allOptions = Arrays.asList(new
> >> String[]{"optionA","optionB","optionC","optionD"});
> >> new CheckBoxMultipleChoice("genreChoice", new PropertyModel(getModel(),
> >> "mySelectedOptions")), allOptions);
> >>
> >> Of course this does not work. But is there a elegant solution to make it
> >> work? I am thinking of something acting similar to a converter for text
> >> input fields, just the other way round :)
> >>
> >> Thanks for any inspiration
> >> --
> >> View this message in context:
> >>
> http://www.nabble.com/How-to-feed-ListMultipleChoice-with-comma-separated-String-via-PropertyModel%29-tp20834160p20834160.html
> >> Sent from the Wicket - User mailing list archive at Nabble.com.
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: [EMAIL PROTECTED]
> >> For additional commands, e-mail: [EMAIL PROTECTED]
> >>
> >>
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/How-to-feed-ListMultipleChoice-with-comma-separated-String-via-PropertyModel%29-tp20834160p20835144.html
> Sent from the Wicket - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>

Reply via email to