Wicket: DropDown box with checkboxes for multiple selection

I need to compactly represent multi-select in the drop-down list in Wicket by checking the box next to each value in the drop-down list. I am thinking of using a ListView with CheckBox and Label as a component for DropDownChoice, but then I'm not sure how to proceed further.

+4
source share
2 answers

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> 
+3
source

Alas Wicket is used to generate HTML, and in HTML there is no way to have a drop down list with checkboxes. (In Swing or another Windowing user interface, this would be possible, and your approach would be correct.)

Look on the Internet, for example, code for HTML, which can cause a similar effect (for example, <div> , which is displayed / not displayed when you click on the edited value). For example, I found this topic here: http://www.webdeveloper.com/forum/showthread.php?t=182976

+1
source

Source: https://habr.com/ru/post/1335462/


All Articles