weixin_33749242 2015-11-10 13:41 采纳率: 0%
浏览 38

wicket测试发送ajax请求

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

  • 写回答

1条回答 默认 最新

  • weixin_33727510 2015-11-11 20:49
    关注

    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)

    评论

报告相同问题?

悬赏问题

  • ¥15 已知平面坐标系(非直角坐标系)内三个点的坐标,反求两坐标轴的夹角
  • ¥15 webots有问题,无响应
  • ¥15 数据量少可以用MK趋势分析吗
  • ¥15 使用VH6501干扰RTR位,CANoe上显示的错误帧不足32个就进入bus off快慢恢复,为什么?
  • ¥15 大智慧怎么编写一个选股程序
  • ¥100 python 调用 cgps 命令获取 实时位置信息
  • ¥15 两台交换机分别是trunk接口和access接口为何无法通信,通信过程是如何?
  • ¥15 C语言使用vscode编码错误
  • ¥15 用KSV5转成本时,如何不生成那笔中间凭证
  • ¥20 ensp怎么配置让PC1和PC2通讯上