You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by de...@dasberg.nl on 2009/07/31 22:41:47 UTC
Testing RadioChoice with AjaxFormComponentUpdatingBehavior
Hi all,
I am trying to test the ajax behaviour on a RadioChoice.
The RadioChoice has an AjaxFormComponentUpdatingBehavior which show/hide a
panel depending on its model value.
final Label label = new Label("label", "label");
label.setOutputMarkupId(true);
label.setVisible(false);
RadioChoice<Boolean> choice = new RadioChoice<Boolean>("choice",
Arrays.asList(Boolean.TRUE, Boolean.FALSE));
choice.add(new AjaxFormChoiceComponentUpdatingBehavior() {
@Override
protected void onUpdate(AjaxRequestTarget target) {
RadioChoice<Boolean> choice = (RadioChoice<Boolean>)
getComponent();
choice.updateModel();
if(choice.getModelObject() == Boolean.TRUE) {
label.setVisible(true);
} else {
label.setVisible(false);
}
target.addComponent(label);
}
});
Now I can trigger the ajax behaviour by doing this:
tester.executeBehavior((AbstractAjaxBehavior)
getComponent("choice").getBehaviors().get(0));
now if I wanna check if the label component is visible I can do the
following:
tester.assertVisible("choice");
The problem is that the label isn't visible because the
respond(AjaxRequestTarget) method on
AjaxFormChoiceComponentUpdatingBehavior
calls the getConvertedInput() method which sets the model to null.
I cannot use the formtester because I just need to check the visibility.
Does anybody know how to handle this?
Kind regards,
Mischa
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Testing RadioChoice with AjaxFormComponentUpdatingBehavior
Posted by de...@dasberg.nl.
Since nobody replied (yet) and I cannot believe that I am the only one
having this problem, and I found a way to bypass the problem I wanted to
share my solution
The executeBehavior method on the WicketTester looks like this.
public void executeBehavior(final AbstractAjaxBehavior behavior) {
CharSequence url = behavior.getCallbackUrl(false);
WebRequestCycle cycle = setupRequestAndResponse(true);
getServletRequest().setRequestToRedirectString(url.toString());
processRequestCycle(cycle);
}
During debugging I found out that the first thing that
getServletRequest().setRequestToRedirectString(url.toString());
does is
parameters.clear();
The problem is that I need the parameter because I want to know the value I
selected on the Component
that the Behavior is added to.
So i created a method on my Base Test class which looks like this:
public void executeBehavior(String id, String value) {
AbstractAjaxBehavior behavior = getComponentAjaxBehaviour(id);
CharSequence url = behavior.getCallbackUrl(false);
WebRequestCycle cycle = tester.setupRequestAndResponse(true);
tester.getServletRequest().setRequestToRedirectString(url.toString());
tester.getServletRequest().setParameter(id, value);
tester.processRequestCycle(cycle);
}
As you can see it doesn't look very different from the WicketTester version
only that
I set the parameter before I call tester.processRequestCycle(cycle);
So now I can test my behavior. I don't know if this is the best way to go,
but for now
I don't see any other way.
Kind regards,
Mischa
On Fri, 31 Jul 2009 22:41:47 +0200, <de...@dasberg.nl> wrote:
> Hi all,
>
> I am trying to test the ajax behaviour on a RadioChoice.
>
> The RadioChoice has an AjaxFormComponentUpdatingBehavior which show/hide
a
> panel depending on its model value.
>
>
> final Label label = new Label("label", "label");
> label.setOutputMarkupId(true);
> label.setVisible(false);
>
> RadioChoice<Boolean> choice = new RadioChoice<Boolean>("choice",
> Arrays.asList(Boolean.TRUE, Boolean.FALSE));
> choice.add(new AjaxFormChoiceComponentUpdatingBehavior() {
> @Override
> protected void onUpdate(AjaxRequestTarget target) {
> RadioChoice<Boolean> choice = (RadioChoice<Boolean>)
> getComponent();
> choice.updateModel();
> if(choice.getModelObject() == Boolean.TRUE) {
> label.setVisible(true);
> } else {
> label.setVisible(false);
> }
> target.addComponent(label);
> }
> });
>
> Now I can trigger the ajax behaviour by doing this:
>
>
> tester.executeBehavior((AbstractAjaxBehavior)
> getComponent("choice").getBehaviors().get(0));
>
> now if I wanna check if the label component is visible I can do the
> following:
>
> tester.assertVisible("choice");
>
> The problem is that the label isn't visible because the
> respond(AjaxRequestTarget) method on
> AjaxFormChoiceComponentUpdatingBehavior
> calls the getConvertedInput() method which sets the model to null.
>
> I cannot use the formtester because I just need to check the visibility.
>
> Does anybody know how to handle this?
>
> Kind regards,
>
> Mischa
>
> ---------------------------------------------------------------------
> 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