public MyComponent extends Panel {
public MyComponent(String id, Component... componentsToRefresh) {
add(new AjaxLink<Void>("someId") {
@Override
public void onClick(AjaxRequestTarget target) {
// some logic with model change
for(Component c: componentsToRefresh) {
c.modelChanged();
}
target.add(componentsToRefresh);
}
};
}
}
我会建议改用三柱门事件系统。也就是说,无论何时单击AjaxLink,您都将广播一个事件:
send(getPage(), Broadcast.BREATH, new MyEventPayload(target));
这将把事件广播到当前页及其所有组件。
然后,在您的任何组件中,您都可以监听事件:
@Override
public void onEvent(IEvent event) {
Object payload = event.getPayload();
if (payload instanceof MyEventPayload) {
((MyEventPayload) payload).getTarget().add(this); // or any of my sub-components
event.stop(); // optionally you can stop the broadcasting
}
}