I've encountered some days ago the following Problem: I have a Page.class with 2 panels. Panel 1 for example gets a click on a Datatable.
@Override
protected void onRowClick(final AjaxRequestTarget target, final Item<Template> item) {
this.send(this.getPage(), Broadcast.BREADTH, new CustomAjaxEvent(target));
}
Custom Ajax Event is holding the RequestTarget, and will be used later to identify the triggered event in another panel.
Now in my second panel I've the following method:
@Override
public void onEvent(IEvent<?> event) {
Object payload = event.getPayload();
if(payload instanceof CustomAjaxEvent){
((CustomAjaxEvent)payload).target.add(this)
}
super.onEvent(event);
}
Now I'm going to test this stuff.. (following code is in testClass)
panel.send(panel.getPage(),
Broadcast.BREADTH,
new CustomAjaxEvent(RequestCycle.get().find(AjaxRequestTarget.class)));
Nullpointer exception occurs on "target.add(this)" from codeblock 2
Of course it is null.. There is no request.
The question is how can I trigger the second codeblock? Access to panel 1 is not given, because I test panel 2 only. Which implies, that I can't click a row in the dataTable and let panel 1 trigger the event.
EDIT: I'm using wicket 6.18
I guess it exist another answer, but in this case it helped me enough:
I created an AjaxRequestTarget mock and send the event. I verify that this method get called. ajaxMockTarget.add(component)