formTester.submit("deleteButton") failed because component with
"deleteButton" id was a SubmitLink.

The following code works:
formTester.submitLink("deleteButton", false);

On Thu, Dec 31, 2009 at 2:38 PM, Alec Swan <[email protected]> wrote:
> Note that the code works on the live system. In other words, records
> selected by the user get deleted from the database when the user
> submits the form.
>
> I'd appreciate any thoughts on why formTester.submit("deleteButton")
> deselects each checkbox before submitting the form.
>
> Thanks
>
> On Thu, Dec 31, 2009 at 11:30 AM, Alec Swan <[email protected]> wrote:
>> 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