You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Merlijn <lu...@gmail.com> on 2013/04/30 12:45:41 UTC

Saving checked choices from CheckGroup

Hi everybody,

I am making a filter for a searchfield where users can choose which items
they want to choose. For this I am using a CheckGroup to show all the
options. Now, whenever I choose an item and use the submit button, the other
items get removed from the list. How can I make sure that the checked
choices get remembered and the non-checked kept in the list?

Kind regards,

Merlijn



--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Saving-checked-choices-from-CheckGroup-tp4658408.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: Saving checked choices from CheckGroup

Posted by Merlijn <lu...@gmail.com>.
Well, the first problem is solved :)

I just want to be able to check a number of checkboxes and use the list of
values that correspond with the values of the Checks in another panel. I
currently have the following but does not seem to work. I also do not want
to use AjaxFormChoiceUpdatingBehaviour as it otherwise does a post whenever
someone checks or unchecks an item. 

    public QuickSearchFilterPanel(String id) {
        super(id);
        form = new Form("filterform");
        types = resultItemHandlerPool.getTypes();

        checkGroup = new CheckGroup<Class&lt;?>>("checkGroup", new
ArrayList<Class&lt;?>>());


        ListView typesListview = new ListView<Class&lt;?>>("typesList",
resultItemHandlerPool.getTypes()) {
            @Override
            protected void populateItem(final ListItem<Class&lt;?>> item) {
                Check c = new Check<Class&lt;?>>("check", item.getModel());
                item.add(c);
                item.add(new Label("className",
item.getModelObject().getSimpleName()));
            }
        };
        typesListview.setReuseItems(true);

        checkGroup.add(typesListview);

        form.add(checkGroup);
        add(form);
    }

    public List<Class&lt;?>> getSearchableTypes() {
      return types;
    }



--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Saving-checked-choices-from-CheckGroup-tp4658408p4658490.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: Saving checked choices from CheckGroup

Posted by Paul Bors <pa...@bors.ws>.
Create a QuickStart and share it with us.

~ Thank you,
   Paul Bors

On Tue, Apr 30, 2013 at 7:17 AM, Merlijn <lu...@gmail.com> wrote:

> Nope, added in the code. This is my code
>
>  public QuickSearchFilterPanel(String id) {
>         super(id);
>         Form form = new Form("filterform");
>
>         List<Class&lt;?>> classes = resultItemHandlerPool.getTypes();
>         types = new ArrayList<IModel&lt;Class&lt;?>>>();
>
>         if (classes != null) {
>             for (final Class<?> clazz : classes) {
>                 IModel<Class&lt;?>> model = new IModel<Class&lt;?>>() {
>                     @Override
>                     public Class<?> getObject() {
>                         return clazz;
>                     }
>
>                     @Override
>                     public void setObject(Class<?> object) {
>
>                     }
>
>                     @Override
>                     public void detach() {
>
>                     }
>                 };
>
>                 types.add(model);
>             }
>         }
>
>         group = new CheckGroup<IModel&lt;Class&lt;?>>>("checkboxgroup", new
> PropertyModel<Collection&lt;IModel&lt;Class&lt;?>>>>(this, "types"));
>         group.add(new CheckGroupSelector("checkall"));
>
>         ListView typesListview = new
> ListView<IModel&lt;Class&lt;?>>>("typesList", new
> PropertyModel<List&lt;IModel&lt;Class&lt;?>>>>(this, "types")) {
>             @Override
>             protected void populateItem(final
> ListItem<IModel&lt;Class&lt;?>>> item) {
>                 final IModel<Class&lt;?>> classModel =
> item.getModelObject();
>                 Check checkbox = new Check<Class&lt;?>>("check",
> classModel);
>                 Label className = new Label("className",
> classModel.getObject().getSimpleName());
>                 item.add(checkbox, className);
>             }
>         };
>         typesListview.setReuseItems(true);
>         group.add(typesListview);
>         form.add(group);
>
>         Button saveButton = new Button("saveButton") {
>             @Override
>             public void onSubmit() {
>                 super.onSubmit();
>             }
>         };
>         form.add(saveButton);
>         add(form);
>     }
>
>     public List<Class&lt;?>> getSearchableTypes() {
>         List<Class&lt;?>> searchableTypes = new ArrayList<Class&lt;?>>();
>
>         for (IModel<Class&lt;?>> type : types) {
>             searchableTypes.add(type.getObject());
>         }
>         return searchableTypes;
>
>     }
>
>
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/Saving-checked-choices-from-CheckGroup-tp4658408p4658411.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: Saving checked choices from CheckGroup

Posted by Merlijn <lu...@gmail.com>.
Nope, added in the code. This is my code 

 public QuickSearchFilterPanel(String id) {
        super(id);
        Form form = new Form("filterform");

        List<Class&lt;?>> classes = resultItemHandlerPool.getTypes();
        types = new ArrayList<IModel&lt;Class&lt;?>>>();

        if (classes != null) {
            for (final Class<?> clazz : classes) {
                IModel<Class&lt;?>> model = new IModel<Class&lt;?>>() {
                    @Override
                    public Class<?> getObject() {
                        return clazz;
                    }

                    @Override
                    public void setObject(Class<?> object) {

                    }

                    @Override
                    public void detach() {

                    }
                };

                types.add(model);
            }
        }

        group = new CheckGroup<IModel&lt;Class&lt;?>>>("checkboxgroup", new
PropertyModel<Collection&lt;IModel&lt;Class&lt;?>>>>(this, "types"));
        group.add(new CheckGroupSelector("checkall"));

        ListView typesListview = new
ListView<IModel&lt;Class&lt;?>>>("typesList", new
PropertyModel<List&lt;IModel&lt;Class&lt;?>>>>(this, "types")) {
            @Override
            protected void populateItem(final
ListItem<IModel&lt;Class&lt;?>>> item) {
                final IModel<Class&lt;?>> classModel =
item.getModelObject();
                Check checkbox = new Check<Class&lt;?>>("check",
classModel);
                Label className = new Label("className",
classModel.getObject().getSimpleName());
                item.add(checkbox, className);
            }
        };
        typesListview.setReuseItems(true);
        group.add(typesListview);
        form.add(group);

        Button saveButton = new Button("saveButton") {
            @Override
            public void onSubmit() {
                super.onSubmit();
            }
        };
        form.add(saveButton);
        add(form);
    }

    public List<Class&lt;?>> getSearchableTypes() {
        List<Class&lt;?>> searchableTypes = new ArrayList<Class&lt;?>>();

        for (IModel<Class&lt;?>> type : types) {
            searchableTypes.add(type.getObject());
        }
        return searchableTypes;

    }



--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Saving-checked-choices-from-CheckGroup-tp4658408p4658411.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: Saving checked choices from CheckGroup

Posted by Martin Grigorov <mg...@apache.org>.
Hi,

it sounds like you need listView.setReuseItems(true)


On Tue, Apr 30, 2013 at 12:45 PM, Merlijn <lu...@gmail.com> wrote:

> Hi everybody,
>
> I am making a filter for a searchfield where users can choose which items
> they want to choose. For this I am using a CheckGroup to show all the
> options. Now, whenever I choose an item and use the submit button, the
> other
> items get removed from the list. How can I make sure that the checked
> choices get remembered and the non-checked kept in the list?
>
> Kind regards,
>
> Merlijn
>
>
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/Saving-checked-choices-from-CheckGroup-tp4658408.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
>
>


-- 
Martin Grigorov
Wicket Training & Consulting
http://jWeekend.com <http://jweekend.com/>