ln2v
ln2v

Reputation: 109

Wicket: (how) can I associate an AjaxCheckBox to the CheckGroupSelector?

I have a problem similar to this question: Wicket: can Checkgroup be Ajax enabled?

I'm using a ListView where each Item has a checkbox. I also have a "select all" checkbox. I am using a CheckGroup, CheckGroupSelector and Check and everything works great. Now there is a new requirement to change the state on some other controls on the page when the checkboxes are updated.

Nicktar's suggestion in the above linked question was the first that came to my mind, too, but I haven't been able to find out how it is possible to use AjaxCheckBox with CheckGroup/CheckGroupSelector. According to the doc you have to use Check.

But in this mail from 2008, Igor Vaynberg also states that it is possible to use AjaxCheckBox in a CheckGroup.

I tried it with just replacing where I used Check with the AjaxCheckBox, but it didn't work, the CheckGroupSelector didn't find the checkboxes anymore.

I also looked into using the onSelectionChanged method in CheckGroup, but I'd like to avoid using this as it triggers another roundtrip to the server, as far as I understood.

Can someone give me a hint? Or is there another nice solution for this?

By the way, I'm using Wicket 1.4.

Upvotes: 4

Views: 2749

Answers (1)

Xavi López
Xavi López

Reputation: 27880

Why can't you add an AjaxFormChoiceComponentUpdatingBehavior to the CheckGroup ?

From AjaxFormComponentUpdatingBehavior's JavaDoc:

NOTE: This behavior does not work on Choices or Groups use the AjaxFormChoiceComponentUpdatingBehavior for that.

AjaxFormChoiceComponentUpdatingBehavior is the behavior to use with CheckGroups and RadioGroups. If you used an AjaxFormComponentUpdatingBehavior with the onchange event, you'd run into this bug with IE . AjaxFormChoiceComponentUpdatingBehavior handles this properly, adding onclick event handlers to each of the Checks in the CheckGroup.

As a side note, what Igor stated in that mail, is that CheckBox can be replaced with AjaxCheckBox, not Check. AjaxCheckBox is nothing more than a convenience subclass of CheckBox with an AjaxFormComponentUpdatingBehavior("onclick"), as the sources show.

Upvotes: 1

Related Questions