Note that there are some explanatory texts on larger screens.

plurals
  1. POWicket : how to set checked value in CheckBoxMultipleChoice
    text
    copied!<p>I am using wicket's CheckBoxMultipleChoice to let the user set a list of options. so far it works fine. but then i want to add a "check all" check box that checks all the options in the CheckBoxMultipleChoice and I am having problems with that.</p> <p>here is my initial code</p> <pre><code>ArrayList&lt;String&gt; chosen; List&lt;String&gt; choices = Arrays.asList(new String[]{"Train", "Bus", "Car"}); CheckBoxMultipleChoice myCheck = new CheckBoxMultipleChoice("transport", new Model(chosen), choices)); myCheck.setOutputMarkupId(true); form.add(myCheck); </code></pre> <p>on submit i print out the values of chosen and its "Bus", "Car" etc. as expected.</p> <p>now i am adding a checkbox to check all the choices using ajax:</p> <pre><code>Boolean checkOrNot; final CheckBox checkAll = new CheckBox("checkAll", new Model(checkOrNot)); form.add(checkAll); checkAll.add(new AjaxFormComponentUpdatingBehavior("onchange") { @Override protected void onUpdate(AjaxRequestTarget target) { // here i am not able to set the checkboxes // i tried doing this chosen.clear(); chosen.add(new String("Car")); chosen.add(new String("Train")); myCheck.modelChanged(); // i have also tried recreating the multiple choice myCheck = new CheckBoxMultipleChoice&lt;T&gt;("transport", new Model(chosen), choices); myCheck.setOutputMarkupId(true); target.addComponent(myCgecj); target.addComponent(form); } }); </code></pre> <p>I am running out of ideas and wondering if anyone has any solutions? thanks in advance for any help.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload