I have some problems using non-serializable model objects with a
ListMultipleChoice (LMC).

What I basically want is that a user selects multiple category items in a
HTML Select tag, and that I can programmaticaly access those selected
category objects after a form submit.

I have something like this:
ListMultipleChoice lmc = new ListMultipleChoice("categories", someModel???,
loadableDetachableModelToGetCategories);

Rendering is no problem, but after I select (non-serializable) selectbox
items, and submit the form, the LMC tries to serialize the categories, which
will give an error because I made them non-serializable.

A LoadableDetachableModel (which I normaly use to get objects via a DAO)
doesn't work, since the LMC tries to store the modelObject in it, which is
not possible. (LoadableDetachableModel is readonly.)


For a ListChoice, I solved it by making a custom IModel that stores the Id's
in the IModel, and let it return the associated Entity object. With
something like this:
IModel categoriesModelForLC = new IModel() {
        private Long id;

        @Override
        public Object getObject() {
                return categoriesDao.findById(id);
        }
        
        @Override
        public void setObject(Object object) {
                this.id = ((Category) object).getId();
        }
        
        @Override
        public void detach() {
        }
};
                
Trying to do something similar with a ListMultipleChoice, where I use a
List<Long> ids instead of Long id, fails with the message:
"Updating a ListMultipleChoice works by modifying the underlying model
object in-place, so please make sure that getObject() always returns the
same Collection instance!"

But I cannot use the same Collection instance, because it's not
serializable, and I need to convert from a List of categoryIds to a List of
Categories, and back.


A solution might be to give the ListMultipleChoice a serializable
stripped-down Category object (containing an ID for the server and a String
to render the client) instead full-blown category object, and let the models
work with that stripped-down object. But that feels cumbersome, like the
Data Transfer Object (DTO) anti pattern.

What is the best way to let ListMultipleChoice work with a List of
non-serializable objects?
-- 
View this message in context: 
http://www.nabble.com/ListMultipleChoice-and-non-serializable-List.-Which-Model-to-use--tp22518189p22518189.html
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org

Reply via email to