You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by "Jeffrey S. Schwartz" <js...@citytechinc.com> on 2009/04/29 23:15:57 UTC
Re: How to test AjaxFormChoiceComponentUpdatingBehavior for Radio
Button
I have the same question as the reader from this email:
http://www.nabble.com/How-to-test-AjaxFormChoiceComponentUpdatingBehavior-for-Radio-Button-p21833782.html
I scoured the mailing lists, wiki and the javadoc for a possible
solution. I have attached a quick-start application that shows the
problem. When I run the application the
AjaxFormChoiceComponentUpdatingBehavior works as expected! However,
when I run the unit test and use the tester.executeBehavior method to
call the AjaxFormChoiceComponentUpdatingBehavior, the model is always
null. A snippet of my unit test is below:
FormTester form = tester.newFormTester("form");
System.out.println("form.modelObject=" +
form.getForm().getModelObject());
form.select("radioButtons", 1);
form.submit();
System.out.println("form.modelObject=" +
form.getForm().getModelObject());
Component comp = form.getForm().get("radioButtons");
List<IBehavior> behaviors = comp.getBehaviors();
for (IBehavior i: behaviors) {
if (i instanceof AjaxFormChoiceComponentUpdatingBehavior) {
AjaxFormChoiceComponentUpdatingBehavior a =
(AjaxFormChoiceComponentUpdatingBehavior)i;
//executes the behavior, but clears the object's model
tester.executeBehavior(a);
}
}
Any suggestions would be very helpful.
I am using wicket 1.4-rc2.
Thanks in advance.
-Jeff
Re: How to test AjaxFormChoiceComponentUpdatingBehavior for Radio
Button
Posted by Marat Radchenko <sl...@gmail.com>.
That's what we are using here:
public static void selectAjaxRadio(final WicketTester tester, final
String radioPath) {
final Radio radio = (Radio)
tester.getComponentFromLastRenderedPage(radioPath);
final RadioGroup radioGroup = radio.findParent(RadioGroup.class);
AjaxFormChoiceComponentUpdatingBehavior behavior = null;
for (final IBehavior b : radioGroup.getBehaviors()) {
if (b instanceof AjaxFormChoiceComponentUpdatingBehavior) {
behavior = (AjaxFormChoiceComponentUpdatingBehavior) b;
break;
}
}
assert behavior != null;
final CharSequence url = behavior.getCallbackUrl(false);
final WebRequestCycle cycle = tester.setupRequestAndResponse(true);
tester.getServletRequest().setRequestToRedirectString(url.toString());
tester.getServletRequest().setParameter(
radioGroup.getInputName(),
radio.getValue()
);
tester.processRequestCycle(cycle);
}
Yep, it looks weird. But works. If you have less hacky solutions,
please, tell us.
2009/4/30 Jeffrey S. Schwartz <js...@citytechinc.com>:
> I have the same question as the reader from this email:
> http://www.nabble.com/How-to-test-AjaxFormChoiceComponentUpdatingBehavior-for-Radio-Button-p21833782.html
>
> I scoured the mailing lists, wiki and the javadoc for a possible
> solution. I have attached a quick-start application that shows the
> problem. When I run the application the
> AjaxFormChoiceComponentUpdatingBehavior works as expected! However,
> when I run the unit test and use the tester.executeBehavior method to
> call the AjaxFormChoiceComponentUpdatingBehavior, the model is always
> null. A snippet of my unit test is below:
>
> FormTester form = tester.newFormTester("form");
> System.out.println("form.modelObject=" +
> form.getForm().getModelObject());
> form.select("radioButtons", 1);
> form.submit();
> System.out.println("form.modelObject=" +
> form.getForm().getModelObject());
>
> Component comp = form.getForm().get("radioButtons");
>
> List<IBehavior> behaviors = comp.getBehaviors();
> for (IBehavior i: behaviors) {
> if (i instanceof AjaxFormChoiceComponentUpdatingBehavior) {
> AjaxFormChoiceComponentUpdatingBehavior a =
> (AjaxFormChoiceComponentUpdatingBehavior)i;
> //executes the behavior, but clears the object's model
> tester.executeBehavior(a);
> }
> }
>
>
> Any suggestions would be very helpful.
>
> I am using wicket 1.4-rc2.
>
> Thanks in advance.
>
> -Jeff
>
>
> ---------------------------------------------------------------------
> 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