Hey Johan,
thanks to your tip, I was able to locate the problem.
As what you said, each time the page was rendered, I added more checkboxes
to the list.
I am using fragment that add checkbox.
What I did instead, was, using a Map instead of a List:
Here is the change:

///// package and import ....
@SuppressWarnings("unchecked")
abstract class EntitiesPanel<E extends ConfigurationEntity> extends Panel {
    private static final long serialVersionUID = -4638085092491297735L;
    private static final int DEFAULT_PAGING = 100;
    private final String configurationName;
    private final Class browserClass;
    private final boolean withSelect;
    private final int paging;
    /** True if all items are selected */
    private boolean allChecked;
    /** Maintains a list of checked items. */
    private final List<EntityWrapper<E>> checkGroupModel = new
ArrayList<EntityWrapper<E>>();
    /** The select-all check box * */
    private MyAjaxCheckBox checkGroup;
    /** Each select boc * */
    /** The list of all entities* */
    private List<EntityWrapper<E>> entitiesList;
    /** The table * */
    private DataTable entityDataTable;

    *private final Map<EntityWrapper, EntityCheckBox> checkboxesMap;*

    @SpringBean(name = "sageDalSecured")
    protected SageDal sageDal;

    EntitiesPanel(String id, String confName, Class browserClass) {
        this(id, confName, browserClass, false, DEFAULT_PAGING);
    }

    EntitiesPanel(String id, String confName, Class browserClass, boolean
withSelect,
            int paging) {
        super(id);
        add(HeaderContributor.forCss(EntitiesPanel.class, "EntitiesPanel.css
"));
        ...
        this.withSelect = withSelect;
        this.configurationName = confName;
        this.browserClass = browserClass;
        this.paging = paging;
        entitiesList = new ArrayList<EntityWrapper<E>>();
        checkboxesMap = new HashMap<EntityWrapper, EntityCheckBox>();
        addCheckGroup();
    }

    final void addToPanel(Set<EntityWrapper<E>> wrappedEntities) {
        setEntitiesList(wrappedEntities);
        final boolean listEmpty = (entitiesList.size() == 0);
        EntityDataProvider entitiesProvider = new
EntityDataProvider(entitiesList,
                getLinkSortProp());
        final List<String> allFields;
        if (listEmpty) {
            allFields = new ArrayList<String>();
        } else {
            allFields = getAllFields(configurationName);
        }
        createTable(entitiesProvider, allFields);
    }

    List<AbstractColumn> getColumnsForTable(List<String> allFields) {
        List<AbstractColumn> columns = new ArrayList<AbstractColumn>();
        for (String field : allFields) {
            columns.add(createColumn(field));
        }
        return columns;
    }

    final PropertyColumn createColumn(final String fieldName) {
        PropertyColumn p = new PropertyColumn(new
Model(getColumnHeader(fieldName)),
                fieldName, fieldName) {
            private static final long serialVersionUID = 1L;

            @Override
            public void populateItem(Item cellItem, String componentId,
IModel rowModel) {
                ConfigurationEntity confEntity = ((EntityWrapper)
rowModel.getObject())
                        .getEntity();
                ...

                Fragment frag = new CellEntityFrag(componentId, "cellFrag",
                        EntitiesPanel.this, strValue);
                cellItem.add(frag);
            }
        };
        return p;
    }

    /** Subclasses can override */
//    protected void onUpdate(AjaxRequestTarget target) {
//    }

    // Private Methods

    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();
                }
                *Collection<EntityCheckBox> checkboxes =
checkboxesMap.values();
                for (EntityCheckBox check : checkboxes) {
                    check.setOutputMarkupId(true);
                    target.addComponent(check);
                }*
                for (EntityWrapper entity : entitiesList) {
                    entity.setSelect(isSelected);
                }
//                EntitiesPanel.this.onUpdate(target);
            }

            @Override
            public boolean isVisible() {
                return (withSelect && entitiesList != null &&
entitiesList.size() > 0);
            }
        };
        checkGroup.setOutputMarkupId(true);
        Label allSelectedLabel = new Label("allSelectedLabel", new
Model(Utils
                .getLocalizationField("allSelected", "entities.label.")));
        add(checkGroup);
        add(allSelectedLabel);
    }

    private void createTable(EntityDataProvider entitiesProvider, final
List<String> allFields) {
        List<AbstractColumn> columns = new ArrayList<AbstractColumn>();
        if (entitiesProvider.size() == 0) {
            columns.add(new AbstractColumn(new Model()) {
                private static final long serialVersionUID = 1L;

                public void populateItem(Item cellItem, String componentId,
IModel rowModel) {
                }
            });
        } else {
            if (withSelect) {
                columns.add(createCheckboxColumn());
            }
            if (allFields.size() > 0) {
                columns.add(createLinkColumn());
                columns.addAll(getColumnsForTable(allFields));
            }
        }
        IColumn[] columnsArray = (IColumn[]) columns.toArray(new
IColumn[0]);
        entityDataTable = new DataTable("entitiesList", columnsArray,
                entitiesProvider, paging);
        add(entityDataTable);
    }

    private AbstractColumn createCheckboxColumn() {
        AbstractColumn p = new AbstractColumn(new Model()) {
            private static final long serialVersionUID = 1L;
            private CheckboxEntityFrag frag;

            public void populateItem(Item cellItem, String componentId,
IModel rowModel) {
                EntityWrapper confEntity = (EntityWrapper)
rowModel.getObject();
                frag = new CheckboxEntityFrag(componentId, "checkboxFrag",
EntitiesPanel.this,
                        confEntity);
                cellItem.add(frag);
            }
        };
        return p;
    }

    private PropertyColumn createLinkColumn() {
        PropertyColumn p = new PropertyColumn(new Model(getLinkHeader()),
getLinkSortProp(),
                getLinkHeader()) {
            private static final long serialVersionUID = 11L;

            @Override
            public void populateItem(Item cellItem, String componentId,
IModel rowModel) {
                ConfigurationEntity confEntity = ((EntityWrapper)
rowModel.getObject())
                        .getEntity();
                Fragment frag = new LinkFrag(componentId, "linkFrag",
EntitiesPanel.this,
                        confEntity);
                cellItem.add(frag);
            }
        };
        return p;
    }

    *private EntityCheckBox getEntityCheckBox(final EntityWrapper
entityWrapper) {
        EntityCheckBox checkbox = checkboxesMap.get(entityWrapper);
        if (checkbox == null) {
            // null indicates that the map doesn't contain this key
            checkbox = new EntityCheckBox(entityWrapper);
            checkboxesMap.put(entityWrapper, checkbox);
        }
        return checkbox;
    }*

    // Fragment Classes

    private class LinkFrag extends Fragment {
        private static final long serialVersionUID = 1L;

        private LinkFrag(String id, String markupId, MarkupContainer
markupProvider,
                ConfigurationEntity confEntity) {
            super(id, markupId, markupProvider);
            PageParameters params = new PageParameters();
            params.put("configurationName", configurationName);
            putOtherParams(params, confEntity);

            PopupSettings popupSettings = new BrowserPopupSettings();
            Link linkToEntity = new BookmarkablePageLink("linkToEntity",
browserClass, params)
                    .setPopupSettings(popupSettings);
            Label label = new Label("markupLabel", new
Model(getLinkLabel(confEntity)));
            linkToEntity.add(label);
            add(linkToEntity);

        }
    }

    private class CellEntityFrag extends Fragment {
        private static final long serialVersionUID = 1L;

        private CellEntityFrag(String id, String markupId, MarkupContainer
markupProvider,
                String value) {
            super(id, markupId, markupProvider);
            Label label = new Label("value", new Model(value));
            add(label);
        }
    }

    private class CheckboxEntityFrag extends Fragment {
        private static final long serialVersionUID = 1L;

        private CheckboxEntityFrag(String id, String markupId,
MarkupContainer markupProvider,
                final EntityWrapper entityWrapper) {
            super(id, markupId, markupProvider);
            *final EntityCheckBox checkbox =
getEntityCheckBox(entityWrapper);*
            add(checkbox);
        }
    }

    // Getters and Setters
    public boolean isAllChecked() {
        return allChecked;
    }

    public void setAllChecked(boolean allChecked) {
        this.allChecked = allChecked;
    }

    public List<EntityWrapper<E>> getCheckGroupModel() {
        return checkGroupModel;
    }

    public List<EntityWrapper<E>> getEntitiesList() {
        return entitiesList;
    }

    public final void setEntitiesList(Collection<EntityWrapper<E>>
entitiesList) {
        this.entitiesList.clear();
        this.entitiesList.addAll(entitiesList);
    }

    // Abstract methods
    abstract String getColumnHeader(String fieldName);

    abstract String getLinkHeader();

    abstract String getLinkLabel(ConfigurationEntity confEntity);

    abstract void putOtherParams(PageParameters params, ConfigurationEntity
confEntity);

    abstract List<String> getAllFields(String configurationName);

    abstract String getLinkSortProp();

    // Private Clases

    private class EntityCheckBox extends MyAjaxCheckBox {
        private static final long serialVersionUID = -3711335571709705139L;
        final EntityWrapper entityWrapper;

        private EntityCheckBox(final EntityWrapper entityWrapper) {
            super("entityCheckbox", new PropertyModel(entityWrapper,
"select"));
            this.entityWrapper = entityWrapper;
        }

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            if (isChecked()) {
                if (!checkGroupModel.contains(entityWrapper))
                    checkGroupModel.add(entityWrapper);
            } else {
                checkGroupModel.remove(entityWrapper);
            }
            setAllChecked(checkGroupModel.size() == entitiesList.size());
            checkGroup.setOutputMarkupId(true);
            target.addComponent(checkGroup);
//            EntitiesPanel.this.onUpdate(target);
        }
    }
}


-- 
Eyal Golan
[EMAIL PROTECTED]

Visit: http://jvdrums.sourceforge.net/

Reply via email to