Wicket 多个组件的AjaxEvent行为相同

Wicket 多个组件的AjaxEvent行为相同,wicket,Wicket,我将图像和文本组件添加到WebMarkupContainer,如下所述: filter.add(newFilterLabel("textSub", customerText, filtervalue)); filter.add(newFilterImage("imgSub", filtervalue)); 对于每个组件,都有一个AjaxEventBehavior执行不同的操作。我想以一种方式对其进行更改,使两者做相同的事情,而不依赖于单击哪个组件 private Component newFi

我将图像和文本组件添加到WebMarkupContainer,如下所述:

filter.add(newFilterLabel("textSub", customerText, filtervalue));
filter.add(newFilterImage("imgSub", filtervalue));
对于每个组件,都有一个AjaxEventBehavior执行不同的操作。我想以一种方式对其进行更改,使两者做相同的事情,而不依赖于单击哪个组件

private Component newFilterLabel(String id, IModel<String> customText,
    final SourceFilterValue currentValue) {
    final BBLabel label = new BBLabel(id, customText);
    label.add(new AjaxEventBehavior("onclick") {
        private static final long serialVersionUID = 1L;

        @Override
        protected void onEvent(AjaxRequestTarget target) {
            doSomething(currentValue,filteredsources, target);
        }
    });
    return label;
}

private Image newFilterImage(String id, final SourceFilterValue filterValue) {
    final Image img = new Image(id, resources.getImage(EXPAND_ICON));
    img.add(new AjaxEventBehavior("onclick") {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onEvent(AjaxRequestTarget target) {
            doSomething(img);
        }
    });
    return img;
}
专用组件newFilterLabel(字符串id、IModel customText、,
最终SourceFilterValue(当前值){
最终BBLabel标签=新BBLabel(id,自定义文本);
label.add(新的AjaxEventBehavior(“onclick”){
私有静态最终长serialVersionUID=1L;
@凌驾
受保护的void onEvent(AjaxRequestTarget目标){
剂量测量(当前值、过滤源、目标);
}
});
退货标签;
}
私有映像newFilterImage(字符串id,最终源filterValue filterValue){
最终图像img=新图像(id,resources.getImage(EXPAND_图标));
添加(新的AjaxEventBehavior(“onclick”){
私有静态最终长serialVersionUID=1L;
@凌驾
受保护的void onEvent(AjaxRequestTarget目标){
剂量测定法(img);
}
});
返回img;
}

您对如何更改它或解决方法有何建议?我使用Wicket 1.5.8。

AjaxBehavior只能绑定到单个元素。将其添加到层次结构中的父级,或者让两种行为调用相同的方法:

@Override
protected void onEvent(AjaxRequestTarget target) {
    doSomething(filterValue); //filterValue has to be final to be able to access it from the inner class
}