you can't hold reference to    checkboxes.add(checkbox); like that
Because onPopulate() can be called again when you refresh the page and then
you get a new set

You can use a reusestrategy for that but still
If you want to set states then you should set states on your model object
that the checkboxes have



On Wed, Mar 12, 2008 at 1:18 PM, Eyal Golan <[EMAIL PROTECTED]> wrote:

> Hi,
> I made a select-all check box inside a table.
> I used the example from
>
> http://javathoughts.capesugarbird.com/2007/09/ajax-select-all-checkbox-for-wicket.html
> It works well in most cases.
>
> Here's some code:
>
> Adding the checkgroup to the panel:
>    private void addCheckGroup() {
>        checkGroup = new MyAjaxCheckBox("allChecked", new
> PropertyModel(this, "allChecked")) {
>            private static final long serialVersionUID = 1L;
>
>            @Override
>            protected void onUpdate(AjaxRequestTarget target) {
>                final boolean isSelected = isChecked();
>                if (isSelected) {
>                    checkGroupModel.addAll(entitiesList);
>                } else {
>                    checkGroupModel.clear();
>                }
>                for (MyAjaxCheckBox check : checkboxes) {
>                    check.setOutputMarkupId(true);
>                    target.addComponent(check);
>                }
>                for (EntityWrapper entity : entitiesList) {
>                    entity.setSelect(isSelected);
>                }
> //                target.addComponent(EntitiesPanel.this);
>                EntitiesPanel.this.onUpdate(target);
>            }
>            @Override
>            public boolean isVisible() {
>                return (withSelect && entitiesList != null &&
> entitiesList.size() > 0);
>            }
>        };
>        checkGroup.setOutputMarkupId(true);
> //        checkGroup.setVisible(false);
>        add(checkGroup);
>    }
>
> The Checkbox column inside the table, and the fragment it uses:
>    private AbstractColumn createCheckboxColumn() {
>        AbstractColumn p = new AbstractColumn(new Model()) {
>            private static final long serialVersionUID = 1L;
>
>            public void populateItem(Item cellItem, String componentId,
> IModel rowModel) {
>                EntityWrapper confEntity = (EntityWrapper)
> rowModel.getObject();
>                Fragment frag = new CheckboxEntityFrag(componentId,
> "checkboxFrag",
>                        EntitiesPanel.this, confEntity);
>                cellItem.add(frag);
>            }
>        };
>        return p;
>    }
>
>        private CheckboxEntityFrag(String id, String markupId,
> MarkupContainer markupProvider,
>                final EntityWrapper value) {
>            super(id, markupId, markupProvider);
>            checkbox = new MyAjaxCheckBox("entityCheckbox", new
> PropertyModel(value, "select")) {
>                private static final long serialVersionUID = 1L;
>
>                @Override
>                protected void onUpdate(AjaxRequestTarget target) {
>                    if (isChecked()) {
>                        if (!checkGroupModel.contains(value))
>                            checkGroupModel.add(value);
>                    } else {
>                        checkGroupModel.remove(value);
>                    }
>                    setAllChecked(checkGroupModel.size() ==
> entitiesList.size());
>                    checkGroup.setOutputMarkupId(true);
>                    target.addComponent(checkGroup);
>                    EntitiesPanel.this.onUpdate(target);
>                }
>            };
>            add(checkbox);
>            checkboxes.add(checkbox);
>        }
>    }
>
> The problem:
> someone else uses my panel for his purposes.
> He has a page (search page) that has my panel (with the table and the
> checkboxes).
> His page has a navigation button - NEXT that uses setResponsePage.
> The next page has a PREV button to go back.
> Going back is also with setResponsePage WITH THE ORIGINAL one.
>
> The scenario:
> Open the search page (with my panel) - the 'select-all' work fine.
> Press next.
> Press back.
>
> Press the 'select-all' again.
> I get an exception: java.lang.IllegalStateException: No Page found for
> component [MarkupContainer [Component id = entityCheckbox, page = <No
> Page>,
> path = 1:cells:1:cell:entityCheckbox.EntitiesPanel$CheckboxEntityFrag$1]]
>
> Is there something in a page's component's life cycle that I'm missing?
>
> Hope it's clear.
>
> (I'll be away for a few days so bare with me if I'm not answering)
>
> Thanks
> --
> Eyal Golan
> [EMAIL PROTECTED]
>
> Visit: http://jvdrums.sourceforge.net/
>

Reply via email to