Hello,
Sorry for the ugly formatting, I hope this will be displayed correctly
below:
Hello,
I need some help with FormTester and Ajax.
I want to test a form, in which the second dropdown is updated in ajax when we
change the first dropdown.
The form is working fine but I can't manage to test it.
DropDownChoice<Company> companyDropDownChoice = new DropDownChoice<>(
"company", LoadableDetachableModel.of( ()-> getCompaniesList() ), new
CompanyChoiceRenderer<>() );
managerDropDownChoice.setRequired( true );
form.add( companyDropDownChoice );
DropDownChoice<User> managerDropDownChoice = new DropDownChoice<>( "manager",
LoadableDetachableModel.of( () ->
getUserList(companyDropDownChoice.getConvertedInput()) ), new
UserChoiceRenderer<>() );
managerDropDownChoice.setRequired( true );
form.add( managerDropDownChoice );
companyDropDownChoice.add( new AjaxFormComponentUpdatingBehavior( "change" ) {
@Override
protected void onUpdate(AjaxRequestTarget target) {
target.add( managerDropDownChoice );
}
} );
//test
FormTester formTester = tester.newFormTester( "form" );
formTester.select( "company", 0 );
tester.executeBehavior( (AbstractAjaxBehavior)
tester.getComponentFromLastRenderedPage( "form:company" ).getBehaviors().get( 0
) );
formTester.select( "manager", 0 ); // Throws
java.lang.IndexOutOfBoundsException: Index 0 out-of-bounds for length 0
Of course I made sure that when the company at index 0, getUserList() returns
some items.
Also, I made sure that when calling tester.executeBehavior, getCompaniesList()
is indeed called.
It's more like if formTester does not update the dropdown...
What am I missing?
Thanks in advance,
Virginie
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]