I have a form which contains a DataView where each row has a checkbox.
The form also contains a submit link which deletes the rows with
selected checkboxes from the database.

The following code uses WicketTester to test the form behavior. The
checkboxes are selected correctly before FormTester.submit(buttonId)
is called. However, FormTester.submit(buttonId) method calls
CheckBox#unselect() on each checkbox before submitting the form. Why
is that?

Thanks,

public void selectAndDeleteRecipients() {
        final FormTester formTester = tester.newFormTester("myForm");
        final Form form = formTester.getForm();
        form.visitChildren(CheckBox.class, new IVisitor<CheckBox>()
        {
            @Override
            public Object component(CheckBox component) {
                final IdCheckBoxModel checkBoxModel =
(IdCheckBoxModel) component.getDefaultModel();
                checkBoxModel.select();
                return CONTINUE_TRAVERSAL;
            }
        });

        formTester.submit("deleteButton"); // this call unselects all
check boxes
    }


/**
 * A checkbox containing an object id.
 */
public class IdCheckBoxModel extends AbstractCheckBoxModel
{
    private final long objectId;

    private final Set selectedIds;

    public IdCheckBoxModel(Long objectId, Set selectedIds) {
        Verify.argumentsNotNull(objectId, selectedIds);
        this.objectId = objectId;
        this.selectedIds = selectedIds;
    }

    public long getObjectId() {
        return objectId;
    }

    @Override
    public boolean isSelected() {
        return selectedIds.contains(objectId);
    }

    @Override
    public void select() {
        selectedIds.add(objectId);
    }

    @Override
    public void unselect() {
        selectedIds.remove(objectId);
    }
}

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to