try the Check/CheckGroup components. they make it really easy to work with listviews, and no wrappers necessary. i believe there is an example of it working with a listview in the component reference.

-Igor


On 2/9/06, Mats Norén <[EMAIL PROTECTED]> wrote:
I'm trying to use a checkbox  in a nested ListView, and I'm having
trouble updating the selection.
I tried the wrapper example in the wiki but it didn't work:

http://www.wicket-wiki.org.uk/wiki/index.php/Listview_with_checkboxes_in_a_form

I'm using wicket 1.2 from february.

Any suggestions?

My code:

ListView searchList = new ListView("rows", new PropertyModel(this,
"searchResult")) {
            public void populateItem(final ListItem listItem) {
                final Party party = (Party) listItem.getModelObject();

                listItem.add(new Label("id", Long.toString(party.getId())));
                listItem.add(new Label("firstname", party.getFirstname()));
                listItem.add(new Label("lastname", party.getLastname()));

                List wrappedPcms = new ArrayList();
                for (PartyContactMechanism pcm :
party.getPartyContactMechanisms()) {
                    wrappedPcms.add(new SelectionWrapper(pcm));
                }

                // Just create a new table, which will be put into the
current cell
                listItem.add(new ListView("contact", wrappedPcms) {
                    public void populateItem(final ListItem listItem) {
                        final SelectionWrapper pcm =
(SelectionWrapper) listItem.getModelObject();
                        listItem.add(new Label("value",
pcm.getPartyContactMechanism().getContactMechanism().getContactMechanismType().getName()));
                         listItem.add(new CheckBox("selected", new
PropertyModel(listItem.getModel(), "selected")));
                    }
                });
            }
        };

        Form resultForm = new Form("resultForm");
        resultForm.add(new Button("add") {
            protected void onSubmit() {
                System.out.println(getForm().getModelObject());
            }
        });
        resultForm.add (searchList);
        add(resultForm);

Where searchList is collection of Party-objects.

The SelectionWrapper:

private class SelectionWrapper implements Serializable {
        private PartyContactMechanism pcm;
        private Boolean selected = Boolean.FALSE;

        public SelectionWrapper(PartyContactMechanism pcm) {
            this.pcm = pcm;
        }

        public Boolean getSelected() {
            return selected;
        }

        public void setSelected(Boolean selected) {
            this.selected = selected;
        }

        public PartyContactMechanism getPartyContactMechanism() {
            return pcm;
        }

        public void setPartyContactMechanism(PartyContactMechanism pcm) {
            this.pcm = pcm;
        }

        public String toString() {
            return pcm.getId() + ": " + selected;
        }
    }


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmdlnk&kid3432&bid#0486&dat1642
_______________________________________________
Wicket-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-user

Reply via email to