I have a data table that I've added a panel into which holds a checkbox in a cell. I have another panel that has a checkbox which I use to select all the checkboxes in the data table. The Select All is done by JQuery and the JQuery is in the code below. How can I get the onclick or onchange event to be called when my JQuery Select All checkbox is checked? I've tried using the AjaxCheckBox below but the event is not being called.
private static List<CheckBox> checkBoxes = new ArrayList<CheckBox>();
private static class ActionsPanel extends Panel {
public ActionsPanel(String id, IModel<WorkOrderCustomer> model, final String uuid ) {
super( id );
AjaxCheckBox checkBox = new AjaxCheckBox("checkbox", Model.of(Boolean.FALSE)) {
private static final long serialVersionUID = 1L;
@Override
protected void onComponentTag(ComponentTag tag) {
super.onComponentTag(tag);
tag.append("class", uuid, " ");
}
@Override
protected void onUpdate(AjaxRequestTarget target) {
if( getModelObject() == true ) {
checkBoxes.add(this);
} else {
checkBoxes.remove(this);
}
}
};
add( checkBox );
}
}
private static class ActivityPanel extends Panel {
private final String selectCheckboxJS = "if($(this).attr('checked') == 'checked') {var val=true;} else {var val=false;}$('." +
uuid + "').each(function() { $(this).attr('checked', val); });"
private static final long serialVersionUID = 1L;
@Inject
private Dao dao;
private DropDownChoice<String> activities;
public ActivityPanel(String id, final String selectCheckboxJS, FilterForm form) {
addActivitySwitchPanel(selectCheckboxJS, form);
}
private void addActivitySwitchPanel(final String selectCheckboxJS, FilterForm form) {
CheckBox checkAll = new CheckBox("checkAll");
checkAll.add(new ChangeActivitySearchBehavior() {
@Override
public void onComponentTag(Component component, ComponentTag tag) {
tag.put("onclick", selectCheckboxJS);
}
});
SubmitLink changeActivityLink = new SubmitLink("activityLink", form);
add( checkAll );
add( changeActivityLink );
}
}
Instead of just changing the value of checked
attribute you could $(this).trigger('click')
on the checkboxes.
Also take a look at org.apache.wicket.markup.html.form.CheckGroupSelector
component.