4
votes

How to implement multiple select drop down in Wicket. I am able to create multi select drop down view using bootstrap but I am not able to get how to relate selected options with IModel of drop down component? Is there any possibility in Wicket? I do not want to use ListMultipleChoice.

1
In general, you should consider using Igor Vaynberg's Select2 library with its Wicket integration: "Select2 is a jQuery based replacement for select boxes. It supports searching, remote data sets, and infinite scrolling of results." - DerMiggel

1 Answers

1
votes

Here is a sample code.

{
 private IModel<List<? extends String>> statusChoices;
 private DropDownChoice<String> status;
 private String statusFilter = "firstChoice";
 // List of Items in drop down
 statusChoices = new AbstractReadOnlyModel<List<? extends String>>() {
     @Override
     public List<String> getObject() {
         List<String> list = new ArrayList<String>();
         list.add("firstChoice");
         list.add("secondChoice");
         list.add("thirdChoice");
         return list;
     }
 };

 status = new DropDownChoice<String>("status",new PropertyModel<String>(this, "statusFilter"), statusChoices);
 status.add(new AjaxFormComponentUpdatingBehavior("onchange") {
     @Override
     protected void onUpdate(AjaxRequestTarget target) {
         if(statusFilter.equals("firstChoice"))
             // Do Somthing
         else
             // Do Somthing
      }
  });
}