You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Virginie Garcin <vi...@equitativa.com> on 2018/04/08 12:22:52 UTC

FormTester and Ajax

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 );	}} );
//testFormTester 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 for 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

Re: FormTester and Ajax

Posted by Sven Meier <sv...@meiers.net>.
Hi,

FormTest#select() sets the value of that component into the request 
*and* submits it - the request is then *cleared* for the upcoming request.

Thus when you call #executeBehavior() afterwards, the request will be 
completely empty and no company is select.
You will have to set the value of that component once again.

Have fun
Sven

Am 08.04.2018 um 14:41 schrieb Virginie Garcin:
> 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: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: FormTester and Ajax

Posted by Virginie Garcin <vi...@equitativa.com>.
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: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org