You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by BrianWilliams <br...@yahoo.com> on 2013/07/19 19:28:02 UTC

Adding checkbox column to DefaultDataTable

This works just fine to add checkboxes to a ListView:
            final CheckGroup<Person> group = new CheckGroup<Person>("group",
new ArrayList<Person>());
            Form<?> form = new Form("form") {
                @Override
                protected void onSubmit() {
                    info("selected person(s): " +
group.getDefaultModelObjectAsString());
                }
            };

            add(form);
            form.add(group);
            group.add(new CheckGroupSelector("groupselector"));
            ListView<Person> listView = new ListView<Person>("persons",
getModel()) {
                /**
                 * @see
                 *
org.apache.wicket.markup.html.list.ListView#populateItem(org.apache.wicket.markup.html.list.ListItem)
                 */
                @Override
                protected void populateItem(ListItem<Person> item) {
                    item.add(new Check<Person>("checkbox",
item.getModel()));
                    item.add(new Label("name", new
PropertyModel<String>(item.getDefaultModel(), "name")));
                }
            };

            listView.setReuseItems(true);
            group.add(listView);

However, similar code to add a checkbox column to a DefaultDataTable fails.  

            final CheckGroup<Person> group = new CheckGroup<Person>("group",
new ArrayList<Person>());
            Form<?> form = new Form("form2") {
                @Override
                protected void onSubmit() {
                    info("selected person(s): " +
group.getDefaultModelObjectAsString());
                }
            };

            List columns = new ArrayList();
            columns.add(new CheckboxColumn("id"));

            columns.add(new PsPropertyColumn("Name", "name") {

                @Override
                public void populateItem(Item cellItem, String componentId,
IModel rowModel)
                {
                    super.populateItem(cellItem, componentId, rowModel);
                }
            });
            final DataProvider dataProvider = new DataProvider(getModel());

            add(form);
            form.add(group);
            group.add(new CheckGroupSelector("groupselector"));
            DefaultDataTable table = new DefaultDataTable("dataTable",
columns, dataProvider, 5) {
            };

            group.add(table);

The checkboxes appear, but selecting on actually selects the column rather
than the individual item.  This causes multiple problems, such as
getDefaultModelObjectAsString() returns the column and the
CheckGroupSelector, thinking the column is selected and the same column is
used for all checkboxes, selects all boxes on post back.  Any advice?





--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Adding-checkbox-column-to-DefaultDataTable-tp4660374.html
Sent from the Users forum mailing list archive at Nabble.com.

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


Re: Adding checkbox column to DefaultDataTable

Posted by BrianWilliams <br...@yahoo.com>.
Sorry to take so long to reply.  I've been working on other things.  Looking
at this again I had to change the model I was using, and my problem is
solved with this CheckboxColumn:

    private class CheckboxColumn<T> extends HeaderlessColumn<T, Object> {

        private String expression;
        public CheckboxColumn(String expression) {
            this.expression = expression;
        }

        @Override
        public Component getHeader(String componentId) {
            return new Label(componentId, new Model<String>("Select"));
            // return new CheckGroupSelector(componentId, checkGroup);
        }

        @Override
        public void populateItem(Item<ICellPopulator&lt;T>> cellItem, String
componentId, IModel<T> rowModel) {
            Panel panel = new CheckboxPanel(componentId, rowModel) {};
            cellItem.add(panel);
            panel.add(new Check("checkbox", rowModel));
        }
    }

Thank you for your consideration.



--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Adding-checkbox-column-to-DefaultDataTable-tp4660374p4660578.html
Sent from the Users forum mailing list archive at Nabble.com.

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


Re: Adding checkbox column to DefaultDataTable

Posted by Sven Meier <sv...@meiers.net>.
What does CheckboxColumn look like?

Sven

On 07/19/2013 07:28 PM, BrianWilliams wrote:
> This works just fine to add checkboxes to a ListView:
>              final CheckGroup<Person> group = new CheckGroup<Person>("group",
> new ArrayList<Person>());
>              Form<?> form = new Form("form") {
>                  @Override
>                  protected void onSubmit() {
>                      info("selected person(s): " +
> group.getDefaultModelObjectAsString());
>                  }
>              };
>
>              add(form);
>              form.add(group);
>              group.add(new CheckGroupSelector("groupselector"));
>              ListView<Person> listView = new ListView<Person>("persons",
> getModel()) {
>                  /**
>                   * @see
>                   *
> org.apache.wicket.markup.html.list.ListView#populateItem(org.apache.wicket.markup.html.list.ListItem)
>                   */
>                  @Override
>                  protected void populateItem(ListItem<Person> item) {
>                      item.add(new Check<Person>("checkbox",
> item.getModel()));
>                      item.add(new Label("name", new
> PropertyModel<String>(item.getDefaultModel(), "name")));
>                  }
>              };
>
>              listView.setReuseItems(true);
>              group.add(listView);
>
> However, similar code to add a checkbox column to a DefaultDataTable fails.
>
>              final CheckGroup<Person> group = new CheckGroup<Person>("group",
> new ArrayList<Person>());
>              Form<?> form = new Form("form2") {
>                  @Override
>                  protected void onSubmit() {
>                      info("selected person(s): " +
> group.getDefaultModelObjectAsString());
>                  }
>              };
>
>              List columns = new ArrayList();
>              columns.add(new CheckboxColumn("id"));
>
>              columns.add(new PsPropertyColumn("Name", "name") {
>
>                  @Override
>                  public void populateItem(Item cellItem, String componentId,
> IModel rowModel)
>                  {
>                      super.populateItem(cellItem, componentId, rowModel);
>                  }
>              });
>              final DataProvider dataProvider = new DataProvider(getModel());
>
>              add(form);
>              form.add(group);
>              group.add(new CheckGroupSelector("groupselector"));
>              DefaultDataTable table = new DefaultDataTable("dataTable",
> columns, dataProvider, 5) {
>              };
>
>              group.add(table);
>
> The checkboxes appear, but selecting on actually selects the column rather
> than the individual item.  This causes multiple problems, such as
> getDefaultModelObjectAsString() returns the column and the
> CheckGroupSelector, thinking the column is selected and the same column is
> used for all checkboxes, selects all boxes on post back.  Any advice?
>
>
>
>
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/Adding-checkbox-column-to-DefaultDataTable-tp4660374.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>


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