MadhaviJ
MadhaviJ

Reputation: 2345

How to select multiple options in dropdown in Apache Wicket?

Is there a way to select multiple values in a dropdown in Apcahe Wicket using PropertyModel?

Upvotes: 2

Views: 1802

Answers (2)

Brijesh pant
Brijesh pant

Reputation: 208

You can use ListMultipleChoice.

Say you have a list of users to which you want to populate in the multiselect drop down. You can do something like this:

ListMultipleChoice<?> multiChoice = new ListMultipleChoice<Object> 
    ("usermultiSelect", 
     (IModel<? extends Collection<Object>>) new PropertyModel<Object>(properties,"selectedUsers"),
     users);

Furthermore you can register on change listener to do some stuff with the selected data

    multichoice.add(new AjaxFormComponentUpdatingBehavior("onchange") {
        private static final long serialVersionUID = 1L;

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            List<User> users = (List<User>) properties.get("selectedUsers");   
            // do whatever you want to do with the users list
        }
    };

Upvotes: 1

Mihir
Mihir

Reputation: 270

You could use wicket Palette or use Select2. https://github.com/ivaynberg/wicket-select2/tree/master/wicket-select2-examples

Upvotes: 0

Related Questions