You can use some javascript library applied to Wicket ListMultipleChoice (which generates an HTML tag [select multiple = "multiple"]. I found one ( jQuery UI MultiSelect Widget hosted on GitHub ) implemented as a jQuery plugin that works very well. Thanks @erichynds !
The page class is just the old Wicket page, and all you have to do is import scripts / stylesheets and call one function (custom):
HomePage.java:
public class HomePage extends WebPage { List<String> selection = new ArrayList<String>(); public HomePage() { add(CSSPackageResource.getHeaderContribution(HomePage.class, "jquery.multiselect.css")); add(JavascriptPackageResource.getHeaderContribution(HomePage.class, "jquery.multiselect.min.js")); add(new FeedbackPanel("feedback")); Form form = new Form("form") { @Override protected void onSubmit() { info(selection.toString()); } }; form.add(new ListMultipleChoice("list", new PropertyModel(this, "selection"), Arrays.asList("A", "B", "C", "D", "E", "F", "G", "H"))); add(form); } }
homepage.html
<html xmlns:wicket="http://wicket.apache.org"> <head> <link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.3/themes/cupertino/jquery-ui.css"> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.3/jquery-ui.min.js"></script> <script type="text/javascript"> $(document).ready(function() { $("select").multiselect(); }); </script> </head> <body> <div wicket:id="feedback"></div> <form wicket:id="form"> <select wicket:id="list"></select> <br/> <input type="submit"> </form> </body> </html>
source share