You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Sjoerd Smeets <ss...@gmail.com> on 2011/03/14 18:53:22 UTC

Checking the checkboxes of CheckBoxMultipleChoice

Hi,

I'm facing an issue where I'm not able to check the checkboxes of a list of
Locations that are already have been persisted in the Details object
(similar like the preselection of checkboxes). I followed the
CheckBoxMultipleChoicePage example
(example<http://wicketstuff.org/wicket13/compref/?wicket:bookmarkablePage=:org.apache.wicket.examples.compref.CheckBoxMultipleChoicePage>
).

So basically when a user wants to edit their detail page, it should select
the checkboxes of the locations the user already selected. saving the form
works fine, so when I select locations, it is persisted correctly to the
details object. Could someone indicate what I am missing?

I have the following code:

public class DetailsPage extends Panel {

    ....
    private final List<Location> LOCATIONS = getLocs();

    public void generateForm(){

        final LocationsInput locationsInput = new LocationsInput(details);
        add(new FeedbackPanel("feedBack"));
        ....

        Form editDetails = new Form("detailsForm"){

            protected void onSubmit() {

                detailsPersistence up = new detailsPersistence();
                details.setLocations(locationsInput.listAsSet());
                logger.info("Saving the following locs:
{}",locationsInput.toString());
                if(newdetails){
                    up.editDetails(details);
                } else {
                    up.updatedetails(details);
                }
                setResponsePage(OverViewDetailssPage.class);
            }
        };

        ...
        CheckBoxMultipleChoice<Location> listChoice =
                new CheckBoxMultipleChoice<Location>("locations",
LOCATIONS);
        listChoice.setDefaultModel(new
CompoundPropertyModel<LocationsInput>(locationsInput));
        listChoice.setModelObject(locationsInput.listAsSet());
        editDetails.add(listChoice);

        add(editDetails);

    }

       private static class LocationsInput implements IClusterable {
        /** the selected sites. */
        public List<Location> locations = new ArrayList();

        public LocationsInput(){
            Location roermond = new Location();
            roermond.setName("Roermond");
            locations.add(roermond);
        }

        /** adds pre-selected items to the choices list */
        public LocationsInput(details details)
        {

            Set<Location> locs = details.getLocations();
            for(Location loc : locs){
                logger.info("details has {} as a location.",loc.getName());
                locations.add(loc);
            }
        }

        @Override
        public String toString(){
            return "locations = " + listAsString(locations);
        }

        private String listAsString(List<Location> list){
            StringBuffer b = new StringBuffer();
            for (Iterator<Location> i = list.iterator(); i.hasNext();){
                b.append(i.next().getName());
                if(i.hasNext()){
                    b.append(", ");
                }
            }
            return b.toString();
        }

        public String[] listAsStringArray(){
            String[] locNames = new String[locations.size()];
            int i =0;
            for(Location loc : locations){
                locNames[i] = loc.getName();
                i++;
            }
            for(String l : locNames){
                logger.info("String array: {}",l);
            }
            return locNames;
        }

        public HashSet<Location> listAsSet(){
            return new HashSet<Location>(locations);
        }
    }

    private List<Location> getLocs(){
        LocationPersistence up4 = new LocationPersistence();
        return up4.getAllLocations();
    }

}

Re: Error on GuiceWebApplicationFactory javadoc

Posted by Martin Grigorov <mg...@apache.org>.
Fixed. Thanks!
Someone forgot to fix it in 1.5

On Mon, Mar 14, 2011 at 8:40 PM, Cristiano Gavião <cv...@gmail.com>wrote:

> Hi,
>
> I'm testing the wicket guice integration. At the GuiceWebApplicationFactory
> class javadoc I could read this example of how to setup web.xml:
>
>  <filter>
>> <filter-name>MyApplication</filter-name>
>> <filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class>
>> <init-param>
>> <param-name>*applicationClassName*</param-name>
>>
>> <param-value>org.apache.wicket.guice.GuiceWebApplicationFactory</param-value>
>> </init-param>
>> <init-param>
>> <param-name>module</param-name>
>>
>> <param-value>com.company.MyGuiceModule,com.company.MyOtherGuiceModule</param-value>
>> </init-param>
>> <init-param>
>> <param-name>wicket-guice.stage</param-name>
>> <param-value>DEVELOPMENT</param-value>
>> </init-param>
>> </filter>
>>
>
> But when I tried to execute it with jetty:run it throws an error:
>
>  Application class org.apache.wicket.guice.GuiceWebApplicationFactory must
>> be a subclass of WebApplication
>>
>
> After debug the org.apache.wicket.protocol.http.WicketFilter I've
> discovered that the right word is: *applicationFactoryClassName *instead
> applicationClassName.
>
>
> cheers
>
> Cristiano
>



-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com <http://jweekend.com/>

Error on GuiceWebApplicationFactory javadoc

Posted by Cristiano Gavião <cv...@gmail.com>.
Hi,

I'm testing the wicket guice integration. At the 
GuiceWebApplicationFactory class javadoc I could read this example of 
how to setup web.xml:

> <filter>
> <filter-name>MyApplication</filter-name>
> <filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class>
> <init-param>
> <param-name>*applicationClassName*</param-name>
> <param-value>org.apache.wicket.guice.GuiceWebApplicationFactory</param-value>
> </init-param>
> <init-param>
> <param-name>module</param-name>
> <param-value>com.company.MyGuiceModule,com.company.MyOtherGuiceModule</param-value>
> </init-param>
> <init-param>
> <param-name>wicket-guice.stage</param-name>
> <param-value>DEVELOPMENT</param-value>
> </init-param>
> </filter>

But when I tried to execute it with jetty:run it throws an error:

> Application class org.apache.wicket.guice.GuiceWebApplicationFactory 
> must be a subclass of WebApplication

After debug the org.apache.wicket.protocol.http.WicketFilter I've 
discovered that the right word is: *applicationFactoryClassName *instead 
applicationClassName.


cheers

Cristiano

Re: Checking the checkboxes of CheckBoxMultipleChoice

Posted by Bruno Borges <br...@gmail.com>.
I wrote a comment on this issue explaining why it is not a bug. Please have
a look.

https://issues.apache.org/jira/browse/WICKET-3538?focusedCommentId=13007777&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-13007777
<https://issues.apache.org/jira/browse/WICKET-3538?focusedCommentId=13007777&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-13007777>
Bruno Borges
www.brunoborges.com.br
+55 21 76727099

"The glory of great men should always be
measured by the means they have used to
acquire it."
 - Francois de La Rochefoucauld



On Tue, Mar 15, 2011 at 3:46 PM, Sjoerd Smeets <ss...@gmail.com> wrote:

> Hi Pedro,
>
> I've created a quickstart and put it in a ticket.
> https://issues.apache.org/jira/browse/WICKET-3538
>
> <https://issues.apache.org/jira/browse/WICKET-3538>Thanks for your help,
> Sjoerd
>
> On Tue, Mar 15, 2011 at 1:12 PM, Pedro Santos <pe...@gmail.com> wrote:
>
> > double check the Location hash/equals implementation, if it keeps not
> > working send us a quickstart
> >
> >
> > On Tue, Mar 15, 2011 at 2:04 PM, Sjoerd Smeets <ss...@gmail.com>
> wrote:
> >
> >> Hi Pedro,
> >>
> >> Thanks for all your help so far. locationsInput.listAsSet() indeed
> returns
> >> the data that is persisted. To try something else, I have created an
> IModel
> >> class called LocationsModel as below and I've changed the concerning bit
> to:
> >>
> >> listChoice.setDefaultModel(new LocationsModel(new
> >> Model(details),details.getLocations()));
> >> //listChoice.setModelObject(locationsInput.listAsSet());
> >>
> >> Unfortunately the result is the same: the data is persisted correctly
> into
> >> my database, but the checkboxes are not checked when the page is
> reloaded or
> >> reopened. I can confirm that details.getLocations() contains all the
> >> locations. Btw, details.getlocations returns a HasSet.
> >>
> >>    private static class LocationsModel implements IModel {
> >>         /** the selected sites. */
> >>        private IModel locationContainingModel;
> >>        private Set<Location> locations;
> >>
> >>        public LocationsModel(IModel locationContainingModel,
> Set<Location>
> >> locations){
> >>            this.locationContainingModel = locationContainingModel;
> >>            this.locations = locations;
> >>        }
> >>
> >>        public Object getObject() {
> >>            Details details = (Details)
> >> locationContainingModel.getObject();
> >>            return details.getLocations();
> >>        }
> >>
> >>        public void setObject(Object object) {
> >>            Details details = (Details)
> >> locationContainingModel.getObject();
> >>            details.setLocations((Set<Location>)object);
> >>        }
> >>
> >>        public void detach() {
> >>            locationContainingModel.detach();
> >>        }
> >>    }
> >>
> >> On Tue, Mar 15, 2011 at 12:22 PM, Pedro Santos <pedrosans@gmail.com
> >wrote:
> >>
> >>> Hi Sjoerd, double check the listChoice. If you want it presenting the
> >>> persisted data, you should use an model containg it, does the
> >>> locationsInput.listAsSet() give you that?
> >>>
> >>> change
> >>>
> >>> listChoice.setDefaultModel(new
> >>> CompoundPropertyModel<LocationsInput>(locationsInput));
> >>> listChoice.setModelObject(locationsInput.listAsSet());
> >>>
> >>> to
> >>>
> >>> listChoice.setDefaultModel(modelContainingCollectionOfPersistedData);
> >>>
> >>> In the example the Input type has an instance variable named: "sites".
> >>> This is exactly the wicket id of the CheckBoxMultipleChoice.
> >>>
> >>> class Input {
> >>>  public List sites = new ArrayList();
> >>> }
> >>>
> >>> final Input input = new Input();
> >>> setModel(new CompoundPropertyModel(input));
> >>> CheckBoxMultipleChoice listChoice = new CheckBoxMultipleChoice("sites",
> >>> SITES);  <-- the model object of thi component will be the "sites" list
> at
> >>> the Input
> >>>
> >>> On Tue, Mar 15, 2011 at 1:00 PM, Sjoerd Smeets <ssmeets@gmail.com
> >wrote:
> >>>
> >>>> Hi Pedro,
> >>>>
> >>>> I've changed the code as you suggested and the result is the same. The
> >>>> data is persisted correctly (as it was in previous cases as well),
> however
> >>>> the check boxes are not checked when the page is reopened. Just to be
> clear,
> >>>>  the locations variable of LocationsInput is set properly when
> >>>>
> >>>> final LocationsInput locationsInput = new LocationsInput(details);
> >>>>
> >>>> is being called. I can also confirm this when I check the variables is
> >>>> debug mode and when I add some extra logging.
> >>>>
> >>>> Am I correct that the checkboxes should be checked when
> >>>> setDefaultModel(new
> >>>> CompoundPropertyModel<LocationsInput>(locationsInput));
> >>>> is called?
> >>>>
> >>>> I understand the purpose of CompoundPropertyModels and PropertyModels.
> >>>> In the example code (example<
> http://wicketstuff.org/wicket13/compref/?wicket:bookmarkablePage=:org.apache.wicket.examples.compref.CheckBoxMultipleChoicePage
> >),
> >>>> the CompoundPropertyModel is used, but it is not exactly clear why to
> me.
> >>>>
> >>>> Could it be that the problem is that in the example an ArrayList of
> >>>> Strings is returned and in my code an ArrayList of Locations is
> returned by
> >>>> the LocationInput class?
> >>>>
> >>>> Alternatively, is there an other way to manually check the checkboxes
> >>>> via loop or something? Performance is of less concern.
> >>>>
> >>>> Thanks again,
> >>>> Sjoerd
> >>>>
> >>>> On Tue, Mar 15, 2011 at 11:03 AM, Pedro Santos <pedrosans@gmail.com
> >wrote:
> >>>>
> >>>>> Your code is not saving the collection of checked locations,
> >>>>>
> >>>>> change
> >>>>>
> >>>>>  details.setLocations(locationsInput.listAsSet());
> >>>>> ...
> >>>>> up.persist(details);
> >>>>>
> >>>>> to
> >>>>>
> >>>>> details.setLocations(listChoice.getModelObject())
> >>>>> ...
> >>>>> up.persist(details);
> >>>>>
> >>>>> and it will start to use the collection in the CheckBoxMultipleChoice
> >>>>> model, so the persisted data will be the user input, and not an new
> >>>>> collection created inside the listAsSet method.
> >>>>>
> >>>>> there is good info about CPM in:
> >>>>>
> https://cwiki.apache.org/WICKET/working-with-wicket-models.html#WorkingwithWicketmodels-CompoundPropertyModels
> >>>>>
> >>>>> On Tue, Mar 15, 2011 at 10:54 AM, Sjoerd Smeets <ssmeets@gmail.com
> >wrote:
> >>>>>
> >>>>>> Hi Pedro,
> >>>>>>
> >>>>>> Thanks for your reply. I'm not sure if I understand what you mean
> with
> >>>>>> "use nested components id as property expressions". The persisting
> >>>>>> part works fine with this code, however checking the correct boxes
> when the
> >>>>>> details page opens does not work. I have tried the following:
> >>>>>> ====
> >>>>>>
> >>>>>> setDefaultModel(new
> CompoundPropertyModel<LocationsInput>(locationsInput));
> >>>>>> ====
> >>>>>>
> >>>>>> listChoice.setDefaultModel(new
> CompoundPropertyModel<LocationsInput>(locationsInput));
> >>>>>> ====
> >>>>>>
> >>>>>> listChoice.setDefaultModel(new
> CompoundPropertyModel<LocationsInput>(locationsInput));
> >>>>>> listChoice.setModelObject(locationsInput.listAsSet());
> >>>>>>
> >>>>>> and they all persist the check checkboxes correctly when the user
> hits
> >>>>>> the submit button, but when reopening the page, the checkboxes are
> not
> >>>>>> checked. What is the easiest way to do this?
> >>>>>>
> >>>>>> Thanks again,
> >>>>>> Sjoerd
> >>>>>>
> >>>>>> On Tue, Mar 15, 2011 at 7:40 AM, Pedro Santos <pedrosans@gmail.com
> >wrote:
> >>>>>>
> >>>>>>> Hi, this code is weird:
> >>>>>>>
> >>>>>>>
> >>>>>>> listChoice.setDefaultModel(new
> CompoundPropertyModel<LocationsInput>(locationsInput));
> >>>>>>>        listChoice.setModelObject(locationsInput.listAsSet());
> >>>>>>>
> >>>>>>> because CompoundPropertyModel is useful to use nested components id
> >>>>>>> as property expressions
> >>>>>>>
> >>>>>>> If details in form submit code is an LocationsInput, then the user
> >>>>>>> input will never be considered.
> >>>>>>>
> >>>>>>> At listAsSet an new collection is created and passed as parameter
> to
> >>>>>>> listChoice:
> >>>>>>> class LocationsInput {
> >>>>>>>         public HashSet<Location> listAsSet(){
> >>>>>>>            return new HashSet<Location>(locations);
> >>>>>>>        }
> >>>>>>> }
> >>>>>>> And a new one is used to be persisted:
> >>>>>>> onSubmit{
> >>>>>>>     details.setLocations(locationsInput.listAsSet());
> >>>>>>>     up.persist(details);
> >>>>>>> }
> >>>>>>>
> >>>>>>> On Mon, Mar 14, 2011 at 2:53 PM, Sjoerd Smeets <ssmeets@gmail.com
> >wrote:
> >>>>>>>
> >>>>>>>>  Hi,
> >>>>>>>>
> >>>>>>>> I'm facing an issue where I'm not able to check the checkboxes of
> a
> >>>>>>>> list of
> >>>>>>>> Locations that are already have been persisted in the Details
> object
> >>>>>>>> (similar like the preselection of checkboxes). I followed the
> >>>>>>>> CheckBoxMultipleChoicePage example
> >>>>>>>> (example<
> >>>>>>>>
> http://wicketstuff.org/wicket13/compref/?wicket:bookmarkablePage=:org.apache.wicket.examples.compref.CheckBoxMultipleChoicePage
> >>>>>>>> >
> >>>>>>>>
> >>>>>>>> ).
> >>>>>>>>
> >>>>>>>> So basically when a user wants to edit their detail page, it
> should
> >>>>>>>> select
> >>>>>>>> the checkboxes of the locations the user already selected. saving
> >>>>>>>> the form
> >>>>>>>> works fine, so when I select locations, it is persisted correctly
> to
> >>>>>>>> the
> >>>>>>>> details object. Could someone indicate what I am missing?
> >>>>>>>>
> >>>>>>>> I have the following code:
> >>>>>>>>
> >>>>>>>> public class DetailsPage extends Panel {
> >>>>>>>>
> >>>>>>>>    ....
> >>>>>>>>    private final List<Location> LOCATIONS = getLocs();
> >>>>>>>>
> >>>>>>>>    public void generateForm(){
> >>>>>>>>
> >>>>>>>>        final LocationsInput locationsInput = new
> >>>>>>>> LocationsInput(details);
> >>>>>>>>        add(new FeedbackPanel("feedBack"));
> >>>>>>>>        ....
> >>>>>>>>
> >>>>>>>>        Form editDetails = new Form("detailsForm"){
> >>>>>>>>
> >>>>>>>>            protected void onSubmit() {
> >>>>>>>>
> >>>>>>>>                detailsPersistence up = new detailsPersistence();
> >>>>>>>>                details.setLocations(locationsInput.listAsSet());
> >>>>>>>>                logger.info("Saving the following locs:
> >>>>>>>> {}",locationsInput.toString());
> >>>>>>>>                if(newdetails){
> >>>>>>>>                    up.editDetails(details);
> >>>>>>>>                } else {
> >>>>>>>>                    up.updatedetails(details);
> >>>>>>>>                }
> >>>>>>>>                setResponsePage(OverViewDetailssPage.class);
> >>>>>>>>            }
> >>>>>>>>        };
> >>>>>>>>
> >>>>>>>>        ...
> >>>>>>>>        CheckBoxMultipleChoice<Location> listChoice =
> >>>>>>>>                new CheckBoxMultipleChoice<Location>("locations",
> >>>>>>>> LOCATIONS);
> >>>>>>>>        listChoice.setDefaultModel(new
> >>>>>>>> CompoundPropertyModel<LocationsInput>(locationsInput));
> >>>>>>>>        listChoice.setModelObject(locationsInput.listAsSet());
> >>>>>>>>        editDetails.add(listChoice);
> >>>>>>>>
> >>>>>>>>        add(editDetails);
> >>>>>>>>
> >>>>>>>>    }
> >>>>>>>>
> >>>>>>>>       private static class LocationsInput implements IClusterable
> {
> >>>>>>>>        /** the selected sites. */
> >>>>>>>>        public List<Location> locations = new ArrayList();
> >>>>>>>>
> >>>>>>>>        public LocationsInput(){
> >>>>>>>>            Location roermond = new Location();
> >>>>>>>>            roermond.setName("Roermond");
> >>>>>>>>            locations.add(roermond);
> >>>>>>>>        }
> >>>>>>>>
> >>>>>>>>        /** adds pre-selected items to the choices list */
> >>>>>>>>        public LocationsInput(details details)
> >>>>>>>>        {
> >>>>>>>>
> >>>>>>>>            Set<Location> locs = details.getLocations();
> >>>>>>>>            for(Location loc : locs){
> >>>>>>>>                logger.info("details has {} as a
> >>>>>>>> location.",loc.getName());
> >>>>>>>>                locations.add(loc);
> >>>>>>>>            }
> >>>>>>>>        }
> >>>>>>>>
> >>>>>>>>        @Override
> >>>>>>>>        public String toString(){
> >>>>>>>>            return "locations = " + listAsString(locations);
> >>>>>>>>        }
> >>>>>>>>
> >>>>>>>>        private String listAsString(List<Location> list){
> >>>>>>>>            StringBuffer b = new StringBuffer();
> >>>>>>>>            for (Iterator<Location> i = list.iterator();
> >>>>>>>> i.hasNext();){
> >>>>>>>>                b.append(i.next().getName());
> >>>>>>>>                if(i.hasNext()){
> >>>>>>>>                    b.append(", ");
> >>>>>>>>                }
> >>>>>>>>            }
> >>>>>>>>            return b.toString();
> >>>>>>>>        }
> >>>>>>>>
> >>>>>>>>        public String[] listAsStringArray(){
> >>>>>>>>            String[] locNames = new String[locations.size()];
> >>>>>>>>            int i =0;
> >>>>>>>>            for(Location loc : locations){
> >>>>>>>>                locNames[i] = loc.getName();
> >>>>>>>>                i++;
> >>>>>>>>            }
> >>>>>>>>            for(String l : locNames){
> >>>>>>>>                logger.info("String array: {}",l);
> >>>>>>>>            }
> >>>>>>>>            return locNames;
> >>>>>>>>        }
> >>>>>>>>
> >>>>>>>>        public HashSet<Location> listAsSet(){
> >>>>>>>>            return new HashSet<Location>(locations);
> >>>>>>>>        }
> >>>>>>>>    }
> >>>>>>>>
> >>>>>>>>    private List<Location> getLocs(){
> >>>>>>>>        LocationPersistence up4 = new LocationPersistence();
> >>>>>>>>        return up4.getAllLocations();
> >>>>>>>>    }
> >>>>>>>>
> >>>>>>>> }
> >>>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>> --
> >>>>>>> Pedro Henrique Oliveira dos Santos
> >>>>>>>
> >>>>>>
> >>>>>>
> >>>>>
> >>>>>
> >>>>> --
> >>>>> Pedro Henrique Oliveira dos Santos
> >>>>>
> >>>>
> >>>>
> >>>
> >>>
> >>> --
> >>> Pedro Henrique Oliveira dos Santos
> >>>
> >>
> >>
> >
> >
> > --
> > Pedro Henrique Oliveira dos Santos
> >
>

Re: Checking the checkboxes of CheckBoxMultipleChoice

Posted by Sjoerd Smeets <ss...@gmail.com>.
Hi Pedro,

I've created a quickstart and put it in a ticket.
https://issues.apache.org/jira/browse/WICKET-3538

<https://issues.apache.org/jira/browse/WICKET-3538>Thanks for your help,
Sjoerd

On Tue, Mar 15, 2011 at 1:12 PM, Pedro Santos <pe...@gmail.com> wrote:

> double check the Location hash/equals implementation, if it keeps not
> working send us a quickstart
>
>
> On Tue, Mar 15, 2011 at 2:04 PM, Sjoerd Smeets <ss...@gmail.com> wrote:
>
>> Hi Pedro,
>>
>> Thanks for all your help so far. locationsInput.listAsSet() indeed returns
>> the data that is persisted. To try something else, I have created an IModel
>> class called LocationsModel as below and I've changed the concerning bit to:
>>
>> listChoice.setDefaultModel(new LocationsModel(new
>> Model(details),details.getLocations()));
>> //listChoice.setModelObject(locationsInput.listAsSet());
>>
>> Unfortunately the result is the same: the data is persisted correctly into
>> my database, but the checkboxes are not checked when the page is reloaded or
>> reopened. I can confirm that details.getLocations() contains all the
>> locations. Btw, details.getlocations returns a HasSet.
>>
>>    private static class LocationsModel implements IModel {
>>         /** the selected sites. */
>>        private IModel locationContainingModel;
>>        private Set<Location> locations;
>>
>>        public LocationsModel(IModel locationContainingModel, Set<Location>
>> locations){
>>            this.locationContainingModel = locationContainingModel;
>>            this.locations = locations;
>>        }
>>
>>        public Object getObject() {
>>            Details details = (Details)
>> locationContainingModel.getObject();
>>            return details.getLocations();
>>        }
>>
>>        public void setObject(Object object) {
>>            Details details = (Details)
>> locationContainingModel.getObject();
>>            details.setLocations((Set<Location>)object);
>>        }
>>
>>        public void detach() {
>>            locationContainingModel.detach();
>>        }
>>    }
>>
>> On Tue, Mar 15, 2011 at 12:22 PM, Pedro Santos <pe...@gmail.com>wrote:
>>
>>> Hi Sjoerd, double check the listChoice. If you want it presenting the
>>> persisted data, you should use an model containg it, does the
>>> locationsInput.listAsSet() give you that?
>>>
>>> change
>>>
>>> listChoice.setDefaultModel(new
>>> CompoundPropertyModel<LocationsInput>(locationsInput));
>>> listChoice.setModelObject(locationsInput.listAsSet());
>>>
>>> to
>>>
>>> listChoice.setDefaultModel(modelContainingCollectionOfPersistedData);
>>>
>>> In the example the Input type has an instance variable named: "sites".
>>> This is exactly the wicket id of the CheckBoxMultipleChoice.
>>>
>>> class Input {
>>>  public List sites = new ArrayList();
>>> }
>>>
>>> final Input input = new Input();
>>> setModel(new CompoundPropertyModel(input));
>>> CheckBoxMultipleChoice listChoice = new CheckBoxMultipleChoice("sites",
>>> SITES);  <-- the model object of thi component will be the "sites" list at
>>> the Input
>>>
>>> On Tue, Mar 15, 2011 at 1:00 PM, Sjoerd Smeets <ss...@gmail.com>wrote:
>>>
>>>> Hi Pedro,
>>>>
>>>> I've changed the code as you suggested and the result is the same. The
>>>> data is persisted correctly (as it was in previous cases as well), however
>>>> the check boxes are not checked when the page is reopened. Just to be clear,
>>>>  the locations variable of LocationsInput is set properly when
>>>>
>>>> final LocationsInput locationsInput = new LocationsInput(details);
>>>>
>>>> is being called. I can also confirm this when I check the variables is
>>>> debug mode and when I add some extra logging.
>>>>
>>>> Am I correct that the checkboxes should be checked when
>>>> setDefaultModel(new
>>>> CompoundPropertyModel<LocationsInput>(locationsInput));
>>>> is called?
>>>>
>>>> I understand the purpose of CompoundPropertyModels and PropertyModels.
>>>> In the example code (example<http://wicketstuff.org/wicket13/compref/?wicket:bookmarkablePage=:org.apache.wicket.examples.compref.CheckBoxMultipleChoicePage>),
>>>> the CompoundPropertyModel is used, but it is not exactly clear why to me.
>>>>
>>>> Could it be that the problem is that in the example an ArrayList of
>>>> Strings is returned and in my code an ArrayList of Locations is returned by
>>>> the LocationInput class?
>>>>
>>>> Alternatively, is there an other way to manually check the checkboxes
>>>> via loop or something? Performance is of less concern.
>>>>
>>>> Thanks again,
>>>> Sjoerd
>>>>
>>>> On Tue, Mar 15, 2011 at 11:03 AM, Pedro Santos <pe...@gmail.com>wrote:
>>>>
>>>>> Your code is not saving the collection of checked locations,
>>>>>
>>>>> change
>>>>>
>>>>>  details.setLocations(locationsInput.listAsSet());
>>>>> ...
>>>>> up.persist(details);
>>>>>
>>>>> to
>>>>>
>>>>> details.setLocations(listChoice.getModelObject())
>>>>> ...
>>>>> up.persist(details);
>>>>>
>>>>> and it will start to use the collection in the CheckBoxMultipleChoice
>>>>> model, so the persisted data will be the user input, and not an new
>>>>> collection created inside the listAsSet method.
>>>>>
>>>>> there is good info about CPM in:
>>>>> https://cwiki.apache.org/WICKET/working-with-wicket-models.html#WorkingwithWicketmodels-CompoundPropertyModels
>>>>>
>>>>> On Tue, Mar 15, 2011 at 10:54 AM, Sjoerd Smeets <ss...@gmail.com>wrote:
>>>>>
>>>>>> Hi Pedro,
>>>>>>
>>>>>> Thanks for your reply. I'm not sure if I understand what you mean with
>>>>>> "use nested components id as property expressions". The persisting
>>>>>> part works fine with this code, however checking the correct boxes when the
>>>>>> details page opens does not work. I have tried the following:
>>>>>> ====
>>>>>>
>>>>>> setDefaultModel(new CompoundPropertyModel<LocationsInput>(locationsInput));
>>>>>> ====
>>>>>>
>>>>>> listChoice.setDefaultModel(new CompoundPropertyModel<LocationsInput>(locationsInput));
>>>>>> ====
>>>>>>
>>>>>> listChoice.setDefaultModel(new CompoundPropertyModel<LocationsInput>(locationsInput));
>>>>>> listChoice.setModelObject(locationsInput.listAsSet());
>>>>>>
>>>>>> and they all persist the check checkboxes correctly when the user hits
>>>>>> the submit button, but when reopening the page, the checkboxes are not
>>>>>> checked. What is the easiest way to do this?
>>>>>>
>>>>>> Thanks again,
>>>>>> Sjoerd
>>>>>>
>>>>>> On Tue, Mar 15, 2011 at 7:40 AM, Pedro Santos <pe...@gmail.com>wrote:
>>>>>>
>>>>>>> Hi, this code is weird:
>>>>>>>
>>>>>>>
>>>>>>> listChoice.setDefaultModel(new CompoundPropertyModel<LocationsInput>(locationsInput));
>>>>>>>        listChoice.setModelObject(locationsInput.listAsSet());
>>>>>>>
>>>>>>> because CompoundPropertyModel is useful to use nested components id
>>>>>>> as property expressions
>>>>>>>
>>>>>>> If details in form submit code is an LocationsInput, then the user
>>>>>>> input will never be considered.
>>>>>>>
>>>>>>> At listAsSet an new collection is created and passed as parameter to
>>>>>>> listChoice:
>>>>>>> class LocationsInput {
>>>>>>>         public HashSet<Location> listAsSet(){
>>>>>>>            return new HashSet<Location>(locations);
>>>>>>>        }
>>>>>>> }
>>>>>>> And a new one is used to be persisted:
>>>>>>> onSubmit{
>>>>>>>     details.setLocations(locationsInput.listAsSet());
>>>>>>>     up.persist(details);
>>>>>>> }
>>>>>>>
>>>>>>> On Mon, Mar 14, 2011 at 2:53 PM, Sjoerd Smeets <ss...@gmail.com>wrote:
>>>>>>>
>>>>>>>>  Hi,
>>>>>>>>
>>>>>>>> I'm facing an issue where I'm not able to check the checkboxes of a
>>>>>>>> list of
>>>>>>>> Locations that are already have been persisted in the Details object
>>>>>>>> (similar like the preselection of checkboxes). I followed the
>>>>>>>> CheckBoxMultipleChoicePage example
>>>>>>>> (example<
>>>>>>>> http://wicketstuff.org/wicket13/compref/?wicket:bookmarkablePage=:org.apache.wicket.examples.compref.CheckBoxMultipleChoicePage
>>>>>>>> >
>>>>>>>>
>>>>>>>> ).
>>>>>>>>
>>>>>>>> So basically when a user wants to edit their detail page, it should
>>>>>>>> select
>>>>>>>> the checkboxes of the locations the user already selected. saving
>>>>>>>> the form
>>>>>>>> works fine, so when I select locations, it is persisted correctly to
>>>>>>>> the
>>>>>>>> details object. Could someone indicate what I am missing?
>>>>>>>>
>>>>>>>> I have the following code:
>>>>>>>>
>>>>>>>> public class DetailsPage extends Panel {
>>>>>>>>
>>>>>>>>    ....
>>>>>>>>    private final List<Location> LOCATIONS = getLocs();
>>>>>>>>
>>>>>>>>    public void generateForm(){
>>>>>>>>
>>>>>>>>        final LocationsInput locationsInput = new
>>>>>>>> LocationsInput(details);
>>>>>>>>        add(new FeedbackPanel("feedBack"));
>>>>>>>>        ....
>>>>>>>>
>>>>>>>>        Form editDetails = new Form("detailsForm"){
>>>>>>>>
>>>>>>>>            protected void onSubmit() {
>>>>>>>>
>>>>>>>>                detailsPersistence up = new detailsPersistence();
>>>>>>>>                details.setLocations(locationsInput.listAsSet());
>>>>>>>>                logger.info("Saving the following locs:
>>>>>>>> {}",locationsInput.toString());
>>>>>>>>                if(newdetails){
>>>>>>>>                    up.editDetails(details);
>>>>>>>>                } else {
>>>>>>>>                    up.updatedetails(details);
>>>>>>>>                }
>>>>>>>>                setResponsePage(OverViewDetailssPage.class);
>>>>>>>>            }
>>>>>>>>        };
>>>>>>>>
>>>>>>>>        ...
>>>>>>>>        CheckBoxMultipleChoice<Location> listChoice =
>>>>>>>>                new CheckBoxMultipleChoice<Location>("locations",
>>>>>>>> LOCATIONS);
>>>>>>>>        listChoice.setDefaultModel(new
>>>>>>>> CompoundPropertyModel<LocationsInput>(locationsInput));
>>>>>>>>        listChoice.setModelObject(locationsInput.listAsSet());
>>>>>>>>        editDetails.add(listChoice);
>>>>>>>>
>>>>>>>>        add(editDetails);
>>>>>>>>
>>>>>>>>    }
>>>>>>>>
>>>>>>>>       private static class LocationsInput implements IClusterable {
>>>>>>>>        /** the selected sites. */
>>>>>>>>        public List<Location> locations = new ArrayList();
>>>>>>>>
>>>>>>>>        public LocationsInput(){
>>>>>>>>            Location roermond = new Location();
>>>>>>>>            roermond.setName("Roermond");
>>>>>>>>            locations.add(roermond);
>>>>>>>>        }
>>>>>>>>
>>>>>>>>        /** adds pre-selected items to the choices list */
>>>>>>>>        public LocationsInput(details details)
>>>>>>>>        {
>>>>>>>>
>>>>>>>>            Set<Location> locs = details.getLocations();
>>>>>>>>            for(Location loc : locs){
>>>>>>>>                logger.info("details has {} as a
>>>>>>>> location.",loc.getName());
>>>>>>>>                locations.add(loc);
>>>>>>>>            }
>>>>>>>>        }
>>>>>>>>
>>>>>>>>        @Override
>>>>>>>>        public String toString(){
>>>>>>>>            return "locations = " + listAsString(locations);
>>>>>>>>        }
>>>>>>>>
>>>>>>>>        private String listAsString(List<Location> list){
>>>>>>>>            StringBuffer b = new StringBuffer();
>>>>>>>>            for (Iterator<Location> i = list.iterator();
>>>>>>>> i.hasNext();){
>>>>>>>>                b.append(i.next().getName());
>>>>>>>>                if(i.hasNext()){
>>>>>>>>                    b.append(", ");
>>>>>>>>                }
>>>>>>>>            }
>>>>>>>>            return b.toString();
>>>>>>>>        }
>>>>>>>>
>>>>>>>>        public String[] listAsStringArray(){
>>>>>>>>            String[] locNames = new String[locations.size()];
>>>>>>>>            int i =0;
>>>>>>>>            for(Location loc : locations){
>>>>>>>>                locNames[i] = loc.getName();
>>>>>>>>                i++;
>>>>>>>>            }
>>>>>>>>            for(String l : locNames){
>>>>>>>>                logger.info("String array: {}",l);
>>>>>>>>            }
>>>>>>>>            return locNames;
>>>>>>>>        }
>>>>>>>>
>>>>>>>>        public HashSet<Location> listAsSet(){
>>>>>>>>            return new HashSet<Location>(locations);
>>>>>>>>        }
>>>>>>>>    }
>>>>>>>>
>>>>>>>>    private List<Location> getLocs(){
>>>>>>>>        LocationPersistence up4 = new LocationPersistence();
>>>>>>>>        return up4.getAllLocations();
>>>>>>>>    }
>>>>>>>>
>>>>>>>> }
>>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> --
>>>>>>> Pedro Henrique Oliveira dos Santos
>>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> Pedro Henrique Oliveira dos Santos
>>>>>
>>>>
>>>>
>>>
>>>
>>> --
>>> Pedro Henrique Oliveira dos Santos
>>>
>>
>>
>
>
> --
> Pedro Henrique Oliveira dos Santos
>

Re: Checking the checkboxes of CheckBoxMultipleChoice

Posted by Sjoerd Smeets <ss...@gmail.com>.
Hi Pedro,

Thanks for all your help so far. locationsInput.listAsSet() indeed returns
the data that is persisted. To try something else, I have created an IModel
class called LocationsModel as below and I've changed the concerning bit to:

listChoice.setDefaultModel(new LocationsModel(new
Model(details),details.getLocations()));
//listChoice.setModelObject(locationsInput.listAsSet());

Unfortunately the result is the same: the data is persisted correctly into
my database, but the checkboxes are not checked when the page is reloaded or
reopened. I can confirm that details.getLocations() contains all the
locations. Btw, details.getlocations returns a HasSet.

   private static class LocationsModel implements IModel {
        /** the selected sites. */
       private IModel locationContainingModel;
       private Set<Location> locations;

       public LocationsModel(IModel locationContainingModel, Set<Location>
locations){
           this.locationContainingModel = locationContainingModel;
           this.locations = locations;
       }

       public Object getObject() {
           Details details = (Details) locationContainingModel.getObject();
           return details.getLocations();
       }

       public void setObject(Object object) {
           Details details = (Details) locationContainingModel.getObject();
           details.setLocations((Set<Location>)object);
       }

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

On Tue, Mar 15, 2011 at 12:22 PM, Pedro Santos <pe...@gmail.com> wrote:

> Hi Sjoerd, double check the listChoice. If you want it presenting the
> persisted data, you should use an model containg it, does the
> locationsInput.listAsSet() give you that?
>
> change
>
> listChoice.setDefaultModel(new
> CompoundPropertyModel<LocationsInput>(locationsInput));
> listChoice.setModelObject(locationsInput.listAsSet());
>
> to
>
> listChoice.setDefaultModel(modelContainingCollectionOfPersistedData);
>
> In the example the Input type has an instance variable named: "sites". This
> is exactly the wicket id of the CheckBoxMultipleChoice.
>
> class Input {
>  public List sites = new ArrayList();
> }
>
> final Input input = new Input();
> setModel(new CompoundPropertyModel(input));
> CheckBoxMultipleChoice listChoice = new CheckBoxMultipleChoice("sites",
> SITES);  <-- the model object of thi component will be the "sites" list at
> the Input
>
> On Tue, Mar 15, 2011 at 1:00 PM, Sjoerd Smeets <ss...@gmail.com> wrote:
>
>> Hi Pedro,
>>
>> I've changed the code as you suggested and the result is the same. The
>> data is persisted correctly (as it was in previous cases as well), however
>> the check boxes are not checked when the page is reopened. Just to be clear,
>>  the locations variable of LocationsInput is set properly when
>>
>> final LocationsInput locationsInput = new LocationsInput(details);
>>
>> is being called. I can also confirm this when I check the variables is
>> debug mode and when I add some extra logging.
>>
>> Am I correct that the checkboxes should be checked when
>> setDefaultModel(new
>> CompoundPropertyModel<LocationsInput>(locationsInput));
>> is called?
>>
>> I understand the purpose of CompoundPropertyModels and PropertyModels. In
>> the example code (example<http://wicketstuff.org/wicket13/compref/?wicket:bookmarkablePage=:org.apache.wicket.examples.compref.CheckBoxMultipleChoicePage>),
>> the CompoundPropertyModel is used, but it is not exactly clear why to me.
>>
>> Could it be that the problem is that in the example an ArrayList of
>> Strings is returned and in my code an ArrayList of Locations is returned by
>> the LocationInput class?
>>
>> Alternatively, is there an other way to manually check the checkboxes via
>> loop or something? Performance is of less concern.
>>
>> Thanks again,
>> Sjoerd
>>
>> On Tue, Mar 15, 2011 at 11:03 AM, Pedro Santos <pe...@gmail.com>wrote:
>>
>>> Your code is not saving the collection of checked locations,
>>>
>>> change
>>>
>>>  details.setLocations(locationsInput.listAsSet());
>>> ...
>>> up.persist(details);
>>>
>>> to
>>>
>>> details.setLocations(listChoice.getModelObject())
>>> ...
>>> up.persist(details);
>>>
>>> and it will start to use the collection in the CheckBoxMultipleChoice
>>> model, so the persisted data will be the user input, and not an new
>>> collection created inside the listAsSet method.
>>>
>>> there is good info about CPM in:
>>> https://cwiki.apache.org/WICKET/working-with-wicket-models.html#WorkingwithWicketmodels-CompoundPropertyModels
>>>
>>> On Tue, Mar 15, 2011 at 10:54 AM, Sjoerd Smeets <ss...@gmail.com>wrote:
>>>
>>>> Hi Pedro,
>>>>
>>>> Thanks for your reply. I'm not sure if I understand what you mean with "use
>>>> nested components id as property expressions". The persisting part works
>>>> fine with this code, however checking the correct boxes when the details
>>>> page opens does not work. I have tried the following:
>>>> ====
>>>>
>>>> setDefaultModel(new CompoundPropertyModel<LocationsInput>(locationsInput));
>>>> ====
>>>>
>>>> listChoice.setDefaultModel(new CompoundPropertyModel<LocationsInput>(locationsInput));
>>>> ====
>>>>
>>>> listChoice.setDefaultModel(new CompoundPropertyModel<LocationsInput>(locationsInput));
>>>> listChoice.setModelObject(locationsInput.listAsSet());
>>>>
>>>> and they all persist the check checkboxes correctly when the user hits
>>>> the submit button, but when reopening the page, the checkboxes are not
>>>> checked. What is the easiest way to do this?
>>>>
>>>> Thanks again,
>>>> Sjoerd
>>>>
>>>> On Tue, Mar 15, 2011 at 7:40 AM, Pedro Santos <pe...@gmail.com>wrote:
>>>>
>>>>> Hi, this code is weird:
>>>>>
>>>>>
>>>>> listChoice.setDefaultModel(new CompoundPropertyModel<LocationsInput>(locationsInput));
>>>>>        listChoice.setModelObject(locationsInput.listAsSet());
>>>>>
>>>>> because CompoundPropertyModel is useful to use nested components id as
>>>>> property expressions
>>>>>
>>>>> If details in form submit code is an LocationsInput, then the user
>>>>> input will never be considered.
>>>>>
>>>>> At listAsSet an new collection is created and passed as parameter to
>>>>> listChoice:
>>>>> class LocationsInput {
>>>>>         public HashSet<Location> listAsSet(){
>>>>>            return new HashSet<Location>(locations);
>>>>>        }
>>>>> }
>>>>> And a new one is used to be persisted:
>>>>> onSubmit{
>>>>>     details.setLocations(locationsInput.listAsSet());
>>>>>     up.persist(details);
>>>>> }
>>>>>
>>>>> On Mon, Mar 14, 2011 at 2:53 PM, Sjoerd Smeets <ss...@gmail.com>wrote:
>>>>>
>>>>>>  Hi,
>>>>>>
>>>>>> I'm facing an issue where I'm not able to check the checkboxes of a
>>>>>> list of
>>>>>> Locations that are already have been persisted in the Details object
>>>>>> (similar like the preselection of checkboxes). I followed the
>>>>>> CheckBoxMultipleChoicePage example
>>>>>> (example<
>>>>>> http://wicketstuff.org/wicket13/compref/?wicket:bookmarkablePage=:org.apache.wicket.examples.compref.CheckBoxMultipleChoicePage
>>>>>> >
>>>>>>
>>>>>> ).
>>>>>>
>>>>>> So basically when a user wants to edit their detail page, it should
>>>>>> select
>>>>>> the checkboxes of the locations the user already selected. saving the
>>>>>> form
>>>>>> works fine, so when I select locations, it is persisted correctly to
>>>>>> the
>>>>>> details object. Could someone indicate what I am missing?
>>>>>>
>>>>>> I have the following code:
>>>>>>
>>>>>> public class DetailsPage extends Panel {
>>>>>>
>>>>>>    ....
>>>>>>    private final List<Location> LOCATIONS = getLocs();
>>>>>>
>>>>>>    public void generateForm(){
>>>>>>
>>>>>>        final LocationsInput locationsInput = new
>>>>>> LocationsInput(details);
>>>>>>        add(new FeedbackPanel("feedBack"));
>>>>>>        ....
>>>>>>
>>>>>>        Form editDetails = new Form("detailsForm"){
>>>>>>
>>>>>>            protected void onSubmit() {
>>>>>>
>>>>>>                detailsPersistence up = new detailsPersistence();
>>>>>>                details.setLocations(locationsInput.listAsSet());
>>>>>>                logger.info("Saving the following locs:
>>>>>> {}",locationsInput.toString());
>>>>>>                if(newdetails){
>>>>>>                    up.editDetails(details);
>>>>>>                } else {
>>>>>>                    up.updatedetails(details);
>>>>>>                }
>>>>>>                setResponsePage(OverViewDetailssPage.class);
>>>>>>            }
>>>>>>        };
>>>>>>
>>>>>>        ...
>>>>>>        CheckBoxMultipleChoice<Location> listChoice =
>>>>>>                new CheckBoxMultipleChoice<Location>("locations",
>>>>>> LOCATIONS);
>>>>>>        listChoice.setDefaultModel(new
>>>>>> CompoundPropertyModel<LocationsInput>(locationsInput));
>>>>>>        listChoice.setModelObject(locationsInput.listAsSet());
>>>>>>        editDetails.add(listChoice);
>>>>>>
>>>>>>        add(editDetails);
>>>>>>
>>>>>>    }
>>>>>>
>>>>>>       private static class LocationsInput implements IClusterable {
>>>>>>        /** the selected sites. */
>>>>>>        public List<Location> locations = new ArrayList();
>>>>>>
>>>>>>        public LocationsInput(){
>>>>>>            Location roermond = new Location();
>>>>>>            roermond.setName("Roermond");
>>>>>>            locations.add(roermond);
>>>>>>        }
>>>>>>
>>>>>>        /** adds pre-selected items to the choices list */
>>>>>>        public LocationsInput(details details)
>>>>>>        {
>>>>>>
>>>>>>            Set<Location> locs = details.getLocations();
>>>>>>            for(Location loc : locs){
>>>>>>                logger.info("details has {} as a
>>>>>> location.",loc.getName());
>>>>>>                locations.add(loc);
>>>>>>            }
>>>>>>        }
>>>>>>
>>>>>>        @Override
>>>>>>        public String toString(){
>>>>>>            return "locations = " + listAsString(locations);
>>>>>>        }
>>>>>>
>>>>>>        private String listAsString(List<Location> list){
>>>>>>            StringBuffer b = new StringBuffer();
>>>>>>            for (Iterator<Location> i = list.iterator(); i.hasNext();){
>>>>>>                b.append(i.next().getName());
>>>>>>                if(i.hasNext()){
>>>>>>                    b.append(", ");
>>>>>>                }
>>>>>>            }
>>>>>>            return b.toString();
>>>>>>        }
>>>>>>
>>>>>>        public String[] listAsStringArray(){
>>>>>>            String[] locNames = new String[locations.size()];
>>>>>>            int i =0;
>>>>>>            for(Location loc : locations){
>>>>>>                locNames[i] = loc.getName();
>>>>>>                i++;
>>>>>>            }
>>>>>>            for(String l : locNames){
>>>>>>                logger.info("String array: {}",l);
>>>>>>            }
>>>>>>            return locNames;
>>>>>>        }
>>>>>>
>>>>>>        public HashSet<Location> listAsSet(){
>>>>>>            return new HashSet<Location>(locations);
>>>>>>        }
>>>>>>    }
>>>>>>
>>>>>>    private List<Location> getLocs(){
>>>>>>        LocationPersistence up4 = new LocationPersistence();
>>>>>>        return up4.getAllLocations();
>>>>>>    }
>>>>>>
>>>>>> }
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> Pedro Henrique Oliveira dos Santos
>>>>>
>>>>
>>>>
>>>
>>>
>>> --
>>> Pedro Henrique Oliveira dos Santos
>>>
>>
>>
>
>
> --
> Pedro Henrique Oliveira dos Santos
>

Re: Checking the checkboxes of CheckBoxMultipleChoice

Posted by Pedro Santos <pe...@gmail.com>.
Hi Sjoerd, double check the listChoice. If you want it presenting the
persisted data, you should use an model containg it, does the
locationsInput.listAsSet() give you that?

change

listChoice.setDefaultModel(new
CompoundPropertyModel<LocationsInput>(locationsInput));
listChoice.setModelObject(locationsInput.listAsSet());

to

listChoice.setDefaultModel(modelContainingCollectionOfPersistedData);

In the example the Input type has an instance variable named: "sites". This
is exactly the wicket id of the CheckBoxMultipleChoice.

class Input {
 public List sites = new ArrayList();
}

final Input input = new Input();
setModel(new CompoundPropertyModel(input));
CheckBoxMultipleChoice listChoice = new CheckBoxMultipleChoice("sites",
SITES);  <-- the model object of thi component will be the "sites" list at
the Input

On Tue, Mar 15, 2011 at 1:00 PM, Sjoerd Smeets <ss...@gmail.com> wrote:

> Hi Pedro,
>
> I've changed the code as you suggested and the result is the same. The data
> is persisted correctly (as it was in previous cases as well), however the
> check boxes are not checked when the page is reopened. Just to be clear,
>  the locations variable of LocationsInput is set properly when
>
> final LocationsInput locationsInput = new LocationsInput(details);
>
> is being called. I can also confirm this when I check the variables is
> debug mode and when I add some extra logging.
>
> Am I correct that the checkboxes should be checked when
> setDefaultModel(new
> CompoundPropertyModel<LocationsInput>(locationsInput));
> is called?
>
> I understand the purpose of CompoundPropertyModels and PropertyModels. In
> the example code (example<http://wicketstuff.org/wicket13/compref/?wicket:bookmarkablePage=:org.apache.wicket.examples.compref.CheckBoxMultipleChoicePage>),
> the CompoundPropertyModel is used, but it is not exactly clear why to me.
>
> Could it be that the problem is that in the example an ArrayList of Strings
> is returned and in my code an ArrayList of Locations is returned by the
> LocationInput class?
>
> Alternatively, is there an other way to manually check the checkboxes via
> loop or something? Performance is of less concern.
>
> Thanks again,
> Sjoerd
>
> On Tue, Mar 15, 2011 at 11:03 AM, Pedro Santos <pe...@gmail.com>wrote:
>
>> Your code is not saving the collection of checked locations,
>>
>> change
>>
>>  details.setLocations(locationsInput.listAsSet());
>> ...
>> up.persist(details);
>>
>> to
>>
>> details.setLocations(listChoice.getModelObject())
>> ...
>> up.persist(details);
>>
>> and it will start to use the collection in the CheckBoxMultipleChoice
>> model, so the persisted data will be the user input, and not an new
>> collection created inside the listAsSet method.
>>
>> there is good info about CPM in:
>> https://cwiki.apache.org/WICKET/working-with-wicket-models.html#WorkingwithWicketmodels-CompoundPropertyModels
>>
>> On Tue, Mar 15, 2011 at 10:54 AM, Sjoerd Smeets <ss...@gmail.com>wrote:
>>
>>> Hi Pedro,
>>>
>>> Thanks for your reply. I'm not sure if I understand what you mean with "use
>>> nested components id as property expressions". The persisting part works
>>> fine with this code, however checking the correct boxes when the details
>>> page opens does not work. I have tried the following:
>>> ====
>>>
>>> setDefaultModel(new CompoundPropertyModel<LocationsInput>(locationsInput));
>>> ====
>>>
>>> listChoice.setDefaultModel(new CompoundPropertyModel<LocationsInput>(locationsInput));
>>> ====
>>>
>>> listChoice.setDefaultModel(new CompoundPropertyModel<LocationsInput>(locationsInput));
>>> listChoice.setModelObject(locationsInput.listAsSet());
>>>
>>> and they all persist the check checkboxes correctly when the user hits
>>> the submit button, but when reopening the page, the checkboxes are not
>>> checked. What is the easiest way to do this?
>>>
>>> Thanks again,
>>> Sjoerd
>>>
>>> On Tue, Mar 15, 2011 at 7:40 AM, Pedro Santos <pe...@gmail.com>wrote:
>>>
>>>> Hi, this code is weird:
>>>>
>>>>
>>>> listChoice.setDefaultModel(new CompoundPropertyModel<LocationsInput>(locationsInput));
>>>>        listChoice.setModelObject(locationsInput.listAsSet());
>>>>
>>>> because CompoundPropertyModel is useful to use nested components id as
>>>> property expressions
>>>>
>>>> If details in form submit code is an LocationsInput, then the user input
>>>> will never be considered.
>>>>
>>>> At listAsSet an new collection is created and passed as parameter to
>>>> listChoice:
>>>> class LocationsInput {
>>>>         public HashSet<Location> listAsSet(){
>>>>            return new HashSet<Location>(locations);
>>>>        }
>>>> }
>>>> And a new one is used to be persisted:
>>>> onSubmit{
>>>>     details.setLocations(locationsInput.listAsSet());
>>>>     up.persist(details);
>>>> }
>>>>
>>>> On Mon, Mar 14, 2011 at 2:53 PM, Sjoerd Smeets <ss...@gmail.com>wrote:
>>>>
>>>>>  Hi,
>>>>>
>>>>> I'm facing an issue where I'm not able to check the checkboxes of a
>>>>> list of
>>>>> Locations that are already have been persisted in the Details object
>>>>> (similar like the preselection of checkboxes). I followed the
>>>>> CheckBoxMultipleChoicePage example
>>>>> (example<
>>>>> http://wicketstuff.org/wicket13/compref/?wicket:bookmarkablePage=:org.apache.wicket.examples.compref.CheckBoxMultipleChoicePage
>>>>> >
>>>>>
>>>>> ).
>>>>>
>>>>> So basically when a user wants to edit their detail page, it should
>>>>> select
>>>>> the checkboxes of the locations the user already selected. saving the
>>>>> form
>>>>> works fine, so when I select locations, it is persisted correctly to
>>>>> the
>>>>> details object. Could someone indicate what I am missing?
>>>>>
>>>>> I have the following code:
>>>>>
>>>>> public class DetailsPage extends Panel {
>>>>>
>>>>>    ....
>>>>>    private final List<Location> LOCATIONS = getLocs();
>>>>>
>>>>>    public void generateForm(){
>>>>>
>>>>>        final LocationsInput locationsInput = new
>>>>> LocationsInput(details);
>>>>>        add(new FeedbackPanel("feedBack"));
>>>>>        ....
>>>>>
>>>>>        Form editDetails = new Form("detailsForm"){
>>>>>
>>>>>            protected void onSubmit() {
>>>>>
>>>>>                detailsPersistence up = new detailsPersistence();
>>>>>                details.setLocations(locationsInput.listAsSet());
>>>>>                logger.info("Saving the following locs:
>>>>> {}",locationsInput.toString());
>>>>>                if(newdetails){
>>>>>                    up.editDetails(details);
>>>>>                } else {
>>>>>                    up.updatedetails(details);
>>>>>                }
>>>>>                setResponsePage(OverViewDetailssPage.class);
>>>>>            }
>>>>>        };
>>>>>
>>>>>        ...
>>>>>        CheckBoxMultipleChoice<Location> listChoice =
>>>>>                new CheckBoxMultipleChoice<Location>("locations",
>>>>> LOCATIONS);
>>>>>        listChoice.setDefaultModel(new
>>>>> CompoundPropertyModel<LocationsInput>(locationsInput));
>>>>>        listChoice.setModelObject(locationsInput.listAsSet());
>>>>>        editDetails.add(listChoice);
>>>>>
>>>>>        add(editDetails);
>>>>>
>>>>>    }
>>>>>
>>>>>       private static class LocationsInput implements IClusterable {
>>>>>        /** the selected sites. */
>>>>>        public List<Location> locations = new ArrayList();
>>>>>
>>>>>        public LocationsInput(){
>>>>>            Location roermond = new Location();
>>>>>            roermond.setName("Roermond");
>>>>>            locations.add(roermond);
>>>>>        }
>>>>>
>>>>>        /** adds pre-selected items to the choices list */
>>>>>        public LocationsInput(details details)
>>>>>        {
>>>>>
>>>>>            Set<Location> locs = details.getLocations();
>>>>>            for(Location loc : locs){
>>>>>                logger.info("details has {} as a
>>>>> location.",loc.getName());
>>>>>                locations.add(loc);
>>>>>            }
>>>>>        }
>>>>>
>>>>>        @Override
>>>>>        public String toString(){
>>>>>            return "locations = " + listAsString(locations);
>>>>>        }
>>>>>
>>>>>        private String listAsString(List<Location> list){
>>>>>            StringBuffer b = new StringBuffer();
>>>>>            for (Iterator<Location> i = list.iterator(); i.hasNext();){
>>>>>                b.append(i.next().getName());
>>>>>                if(i.hasNext()){
>>>>>                    b.append(", ");
>>>>>                }
>>>>>            }
>>>>>            return b.toString();
>>>>>        }
>>>>>
>>>>>        public String[] listAsStringArray(){
>>>>>            String[] locNames = new String[locations.size()];
>>>>>            int i =0;
>>>>>            for(Location loc : locations){
>>>>>                locNames[i] = loc.getName();
>>>>>                i++;
>>>>>            }
>>>>>            for(String l : locNames){
>>>>>                logger.info("String array: {}",l);
>>>>>            }
>>>>>            return locNames;
>>>>>        }
>>>>>
>>>>>        public HashSet<Location> listAsSet(){
>>>>>            return new HashSet<Location>(locations);
>>>>>        }
>>>>>    }
>>>>>
>>>>>    private List<Location> getLocs(){
>>>>>        LocationPersistence up4 = new LocationPersistence();
>>>>>        return up4.getAllLocations();
>>>>>    }
>>>>>
>>>>> }
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> Pedro Henrique Oliveira dos Santos
>>>>
>>>
>>>
>>
>>
>> --
>> Pedro Henrique Oliveira dos Santos
>>
>
>


-- 
Pedro Henrique Oliveira dos Santos

Re: Checking the checkboxes of CheckBoxMultipleChoice

Posted by Sjoerd Smeets <ss...@gmail.com>.
Hi Pedro,

I've changed the code as you suggested and the result is the same. The data
is persisted correctly (as it was in previous cases as well), however the
check boxes are not checked when the page is reopened. Just to be clear,
 the locations variable of LocationsInput is set properly when

final LocationsInput locationsInput = new LocationsInput(details);

is being called. I can also confirm this when I check the variables is debug
mode and when I add some extra logging.

Am I correct that the checkboxes should be checked when
setDefaultModel(new CompoundPropertyModel<LocationsInput>(locationsInput));
is called?

I understand the purpose of CompoundPropertyModels and PropertyModels. In
the example code
(example<http://wicketstuff.org/wicket13/compref/?wicket:bookmarkablePage=:org.apache.wicket.examples.compref.CheckBoxMultipleChoicePage>),
the CompoundPropertyModel is used, but it is not exactly clear why to me.

Could it be that the problem is that in the example an ArrayList of Strings
is returned and in my code an ArrayList of Locations is returned by the
LocationInput class?

Alternatively, is there an other way to manually check the checkboxes via
loop or something? Performance is of less concern.

Thanks again,
Sjoerd

On Tue, Mar 15, 2011 at 11:03 AM, Pedro Santos <pe...@gmail.com> wrote:

> Your code is not saving the collection of checked locations,
>
> change
>
>  details.setLocations(locationsInput.listAsSet());
> ...
> up.persist(details);
>
> to
>
> details.setLocations(listChoice.getModelObject())
> ...
> up.persist(details);
>
> and it will start to use the collection in the CheckBoxMultipleChoice
> model, so the persisted data will be the user input, and not an new
> collection created inside the listAsSet method.
>
> there is good info about CPM in:
> https://cwiki.apache.org/WICKET/working-with-wicket-models.html#WorkingwithWicketmodels-CompoundPropertyModels
>
> On Tue, Mar 15, 2011 at 10:54 AM, Sjoerd Smeets <ss...@gmail.com> wrote:
>
>> Hi Pedro,
>>
>> Thanks for your reply. I'm not sure if I understand what you mean with "use
>> nested components id as property expressions". The persisting part works
>> fine with this code, however checking the correct boxes when the details
>> page opens does not work. I have tried the following:
>> ====
>>
>> setDefaultModel(new CompoundPropertyModel<LocationsInput>(locationsInput));
>> ====
>>
>> listChoice.setDefaultModel(new CompoundPropertyModel<LocationsInput>(locationsInput));
>> ====
>>
>> listChoice.setDefaultModel(new CompoundPropertyModel<LocationsInput>(locationsInput));
>> listChoice.setModelObject(locationsInput.listAsSet());
>>
>> and they all persist the check checkboxes correctly when the user hits the
>> submit button, but when reopening the page, the checkboxes are not checked.
>> What is the easiest way to do this?
>>
>> Thanks again,
>> Sjoerd
>>
>> On Tue, Mar 15, 2011 at 7:40 AM, Pedro Santos <pe...@gmail.com>wrote:
>>
>>> Hi, this code is weird:
>>>
>>>
>>> listChoice.setDefaultModel(new CompoundPropertyModel<LocationsInput>(locationsInput));
>>>        listChoice.setModelObject(locationsInput.listAsSet());
>>>
>>> because CompoundPropertyModel is useful to use nested components id as
>>> property expressions
>>>
>>> If details in form submit code is an LocationsInput, then the user input
>>> will never be considered.
>>>
>>> At listAsSet an new collection is created and passed as parameter to
>>> listChoice:
>>> class LocationsInput {
>>>         public HashSet<Location> listAsSet(){
>>>            return new HashSet<Location>(locations);
>>>        }
>>> }
>>> And a new one is used to be persisted:
>>> onSubmit{
>>>     details.setLocations(locationsInput.listAsSet());
>>>     up.persist(details);
>>> }
>>>
>>> On Mon, Mar 14, 2011 at 2:53 PM, Sjoerd Smeets <ss...@gmail.com>wrote:
>>>
>>>>  Hi,
>>>>
>>>> I'm facing an issue where I'm not able to check the checkboxes of a list
>>>> of
>>>> Locations that are already have been persisted in the Details object
>>>> (similar like the preselection of checkboxes). I followed the
>>>> CheckBoxMultipleChoicePage example
>>>> (example<
>>>> http://wicketstuff.org/wicket13/compref/?wicket:bookmarkablePage=:org.apache.wicket.examples.compref.CheckBoxMultipleChoicePage
>>>> >
>>>>
>>>> ).
>>>>
>>>> So basically when a user wants to edit their detail page, it should
>>>> select
>>>> the checkboxes of the locations the user already selected. saving the
>>>> form
>>>> works fine, so when I select locations, it is persisted correctly to the
>>>> details object. Could someone indicate what I am missing?
>>>>
>>>> I have the following code:
>>>>
>>>> public class DetailsPage extends Panel {
>>>>
>>>>    ....
>>>>    private final List<Location> LOCATIONS = getLocs();
>>>>
>>>>    public void generateForm(){
>>>>
>>>>        final LocationsInput locationsInput = new
>>>> LocationsInput(details);
>>>>        add(new FeedbackPanel("feedBack"));
>>>>        ....
>>>>
>>>>        Form editDetails = new Form("detailsForm"){
>>>>
>>>>            protected void onSubmit() {
>>>>
>>>>                detailsPersistence up = new detailsPersistence();
>>>>                details.setLocations(locationsInput.listAsSet());
>>>>                logger.info("Saving the following locs:
>>>> {}",locationsInput.toString());
>>>>                if(newdetails){
>>>>                    up.editDetails(details);
>>>>                } else {
>>>>                    up.updatedetails(details);
>>>>                }
>>>>                setResponsePage(OverViewDetailssPage.class);
>>>>            }
>>>>        };
>>>>
>>>>        ...
>>>>        CheckBoxMultipleChoice<Location> listChoice =
>>>>                new CheckBoxMultipleChoice<Location>("locations",
>>>> LOCATIONS);
>>>>        listChoice.setDefaultModel(new
>>>> CompoundPropertyModel<LocationsInput>(locationsInput));
>>>>        listChoice.setModelObject(locationsInput.listAsSet());
>>>>        editDetails.add(listChoice);
>>>>
>>>>        add(editDetails);
>>>>
>>>>    }
>>>>
>>>>       private static class LocationsInput implements IClusterable {
>>>>        /** the selected sites. */
>>>>        public List<Location> locations = new ArrayList();
>>>>
>>>>        public LocationsInput(){
>>>>            Location roermond = new Location();
>>>>            roermond.setName("Roermond");
>>>>            locations.add(roermond);
>>>>        }
>>>>
>>>>        /** adds pre-selected items to the choices list */
>>>>        public LocationsInput(details details)
>>>>        {
>>>>
>>>>            Set<Location> locs = details.getLocations();
>>>>            for(Location loc : locs){
>>>>                logger.info("details has {} as a
>>>> location.",loc.getName());
>>>>                locations.add(loc);
>>>>            }
>>>>        }
>>>>
>>>>        @Override
>>>>        public String toString(){
>>>>            return "locations = " + listAsString(locations);
>>>>        }
>>>>
>>>>        private String listAsString(List<Location> list){
>>>>            StringBuffer b = new StringBuffer();
>>>>            for (Iterator<Location> i = list.iterator(); i.hasNext();){
>>>>                b.append(i.next().getName());
>>>>                if(i.hasNext()){
>>>>                    b.append(", ");
>>>>                }
>>>>            }
>>>>            return b.toString();
>>>>        }
>>>>
>>>>        public String[] listAsStringArray(){
>>>>            String[] locNames = new String[locations.size()];
>>>>            int i =0;
>>>>            for(Location loc : locations){
>>>>                locNames[i] = loc.getName();
>>>>                i++;
>>>>            }
>>>>            for(String l : locNames){
>>>>                logger.info("String array: {}",l);
>>>>            }
>>>>            return locNames;
>>>>        }
>>>>
>>>>        public HashSet<Location> listAsSet(){
>>>>            return new HashSet<Location>(locations);
>>>>        }
>>>>    }
>>>>
>>>>    private List<Location> getLocs(){
>>>>        LocationPersistence up4 = new LocationPersistence();
>>>>        return up4.getAllLocations();
>>>>    }
>>>>
>>>> }
>>>>
>>>
>>>
>>>
>>> --
>>> Pedro Henrique Oliveira dos Santos
>>>
>>
>>
>
>
> --
> Pedro Henrique Oliveira dos Santos
>

Re: Checking the checkboxes of CheckBoxMultipleChoice

Posted by Sjoerd Smeets <ss...@gmail.com>.
Hi Pedro,

Thanks for your reply. I'm not sure if I understand what you mean with "use
nested components id as property expressions". The persisting part works
fine with this code, however checking the correct boxes when the details
page opens does not work. I have tried the following:
====
setDefaultModel(new CompoundPropertyModel<LocationsInput>(locationsInput));
====
listChoice.setDefaultModel(new
CompoundPropertyModel<LocationsInput>(locationsInput));
====
listChoice.setDefaultModel(new
CompoundPropertyModel<LocationsInput>(locationsInput));
listChoice.setModelObject(locationsInput.listAsSet());

and they all persist the check checkboxes correctly when the user hits the
submit button, but when reopening the page, the checkboxes are not checked.
What is the easiest way to do this?

Thanks again,
Sjoerd

On Tue, Mar 15, 2011 at 7:40 AM, Pedro Santos <pe...@gmail.com> wrote:

> Hi, this code is weird:
>
>
> listChoice.setDefaultModel(new CompoundPropertyModel<LocationsInput>(locationsInput));
>        listChoice.setModelObject(locationsInput.listAsSet());
>
> because CompoundPropertyModel is useful to use nested components id as
> property expressions
>
> If details in form submit code is an LocationsInput, then the user input
> will never be considered.
>
> At listAsSet an new collection is created and passed as parameter to
> listChoice:
> class LocationsInput {
>         public HashSet<Location> listAsSet(){
>            return new HashSet<Location>(locations);
>        }
> }
> And a new one is used to be persisted:
> onSubmit{
>     details.setLocations(locationsInput.listAsSet());
>     up.persist(details);
> }
>
> On Mon, Mar 14, 2011 at 2:53 PM, Sjoerd Smeets <ss...@gmail.com> wrote:
>
>>  Hi,
>>
>> I'm facing an issue where I'm not able to check the checkboxes of a list
>> of
>> Locations that are already have been persisted in the Details object
>> (similar like the preselection of checkboxes). I followed the
>> CheckBoxMultipleChoicePage example
>> (example<
>> http://wicketstuff.org/wicket13/compref/?wicket:bookmarkablePage=:org.apache.wicket.examples.compref.CheckBoxMultipleChoicePage
>> >
>>
>> ).
>>
>> So basically when a user wants to edit their detail page, it should select
>> the checkboxes of the locations the user already selected. saving the form
>> works fine, so when I select locations, it is persisted correctly to the
>> details object. Could someone indicate what I am missing?
>>
>> I have the following code:
>>
>> public class DetailsPage extends Panel {
>>
>>    ....
>>    private final List<Location> LOCATIONS = getLocs();
>>
>>    public void generateForm(){
>>
>>        final LocationsInput locationsInput = new LocationsInput(details);
>>        add(new FeedbackPanel("feedBack"));
>>        ....
>>
>>        Form editDetails = new Form("detailsForm"){
>>
>>            protected void onSubmit() {
>>
>>                detailsPersistence up = new detailsPersistence();
>>                details.setLocations(locationsInput.listAsSet());
>>                logger.info("Saving the following locs:
>> {}",locationsInput.toString());
>>                if(newdetails){
>>                    up.editDetails(details);
>>                } else {
>>                    up.updatedetails(details);
>>                }
>>                setResponsePage(OverViewDetailssPage.class);
>>            }
>>        };
>>
>>        ...
>>        CheckBoxMultipleChoice<Location> listChoice =
>>                new CheckBoxMultipleChoice<Location>("locations",
>> LOCATIONS);
>>        listChoice.setDefaultModel(new
>> CompoundPropertyModel<LocationsInput>(locationsInput));
>>        listChoice.setModelObject(locationsInput.listAsSet());
>>        editDetails.add(listChoice);
>>
>>        add(editDetails);
>>
>>    }
>>
>>       private static class LocationsInput implements IClusterable {
>>        /** the selected sites. */
>>        public List<Location> locations = new ArrayList();
>>
>>        public LocationsInput(){
>>            Location roermond = new Location();
>>            roermond.setName("Roermond");
>>            locations.add(roermond);
>>        }
>>
>>        /** adds pre-selected items to the choices list */
>>        public LocationsInput(details details)
>>        {
>>
>>            Set<Location> locs = details.getLocations();
>>            for(Location loc : locs){
>>                logger.info("details has {} as a
>> location.",loc.getName());
>>                locations.add(loc);
>>            }
>>        }
>>
>>        @Override
>>        public String toString(){
>>            return "locations = " + listAsString(locations);
>>        }
>>
>>        private String listAsString(List<Location> list){
>>            StringBuffer b = new StringBuffer();
>>            for (Iterator<Location> i = list.iterator(); i.hasNext();){
>>                b.append(i.next().getName());
>>                if(i.hasNext()){
>>                    b.append(", ");
>>                }
>>            }
>>            return b.toString();
>>        }
>>
>>        public String[] listAsStringArray(){
>>            String[] locNames = new String[locations.size()];
>>            int i =0;
>>            for(Location loc : locations){
>>                locNames[i] = loc.getName();
>>                i++;
>>            }
>>            for(String l : locNames){
>>                logger.info("String array: {}",l);
>>            }
>>            return locNames;
>>        }
>>
>>        public HashSet<Location> listAsSet(){
>>            return new HashSet<Location>(locations);
>>        }
>>    }
>>
>>    private List<Location> getLocs(){
>>        LocationPersistence up4 = new LocationPersistence();
>>        return up4.getAllLocations();
>>    }
>>
>> }
>>
>
>
>
> --
> Pedro Henrique Oliveira dos Santos
>

Re: Checking the checkboxes of CheckBoxMultipleChoice

Posted by Pedro Santos <pe...@gmail.com>.
Hi, this code is weird:


listChoice.setDefaultModel(new
CompoundPropertyModel<LocationsInput>(locationsInput));
       listChoice.setModelObject(locationsInput.listAsSet());

because CompoundPropertyModel is useful to use nested components id as
property expressions

If details in form submit code is an LocationsInput, then the user input
will never be considered.

At listAsSet an new collection is created and passed as parameter to
listChoice:
class LocationsInput {
        public HashSet<Location> listAsSet(){
           return new HashSet<Location>(locations);
       }
}
And a new one is used to be persisted:
onSubmit{
    details.setLocations(locationsInput.listAsSet());
    up.persist(details);
}

On Mon, Mar 14, 2011 at 2:53 PM, Sjoerd Smeets <ss...@gmail.com> wrote:

> Hi,
>
> I'm facing an issue where I'm not able to check the checkboxes of a list of
> Locations that are already have been persisted in the Details object
> (similar like the preselection of checkboxes). I followed the
> CheckBoxMultipleChoicePage example
> (example<
> http://wicketstuff.org/wicket13/compref/?wicket:bookmarkablePage=:org.apache.wicket.examples.compref.CheckBoxMultipleChoicePage
> >
> ).
>
> So basically when a user wants to edit their detail page, it should select
> the checkboxes of the locations the user already selected. saving the form
> works fine, so when I select locations, it is persisted correctly to the
> details object. Could someone indicate what I am missing?
>
> I have the following code:
>
> public class DetailsPage extends Panel {
>
>    ....
>    private final List<Location> LOCATIONS = getLocs();
>
>    public void generateForm(){
>
>        final LocationsInput locationsInput = new LocationsInput(details);
>        add(new FeedbackPanel("feedBack"));
>        ....
>
>        Form editDetails = new Form("detailsForm"){
>
>            protected void onSubmit() {
>
>                detailsPersistence up = new detailsPersistence();
>                details.setLocations(locationsInput.listAsSet());
>                logger.info("Saving the following locs:
> {}",locationsInput.toString());
>                if(newdetails){
>                    up.editDetails(details);
>                } else {
>                    up.updatedetails(details);
>                }
>                setResponsePage(OverViewDetailssPage.class);
>            }
>        };
>
>        ...
>        CheckBoxMultipleChoice<Location> listChoice =
>                new CheckBoxMultipleChoice<Location>("locations",
> LOCATIONS);
>        listChoice.setDefaultModel(new
> CompoundPropertyModel<LocationsInput>(locationsInput));
>        listChoice.setModelObject(locationsInput.listAsSet());
>        editDetails.add(listChoice);
>
>        add(editDetails);
>
>    }
>
>       private static class LocationsInput implements IClusterable {
>        /** the selected sites. */
>        public List<Location> locations = new ArrayList();
>
>        public LocationsInput(){
>            Location roermond = new Location();
>            roermond.setName("Roermond");
>            locations.add(roermond);
>        }
>
>        /** adds pre-selected items to the choices list */
>        public LocationsInput(details details)
>        {
>
>            Set<Location> locs = details.getLocations();
>            for(Location loc : locs){
>                logger.info("details has {} as a location.",loc.getName());
>                locations.add(loc);
>            }
>        }
>
>        @Override
>        public String toString(){
>            return "locations = " + listAsString(locations);
>        }
>
>        private String listAsString(List<Location> list){
>            StringBuffer b = new StringBuffer();
>            for (Iterator<Location> i = list.iterator(); i.hasNext();){
>                b.append(i.next().getName());
>                if(i.hasNext()){
>                    b.append(", ");
>                }
>            }
>            return b.toString();
>        }
>
>        public String[] listAsStringArray(){
>            String[] locNames = new String[locations.size()];
>            int i =0;
>            for(Location loc : locations){
>                locNames[i] = loc.getName();
>                i++;
>            }
>            for(String l : locNames){
>                logger.info("String array: {}",l);
>            }
>            return locNames;
>        }
>
>        public HashSet<Location> listAsSet(){
>            return new HashSet<Location>(locations);
>        }
>    }
>
>    private List<Location> getLocs(){
>        LocationPersistence up4 = new LocationPersistence();
>        return up4.getAllLocations();
>    }
>
> }
>



-- 
Pedro Henrique Oliveira dos Santos