我用Vaadin23。
是否有合法的方法来防止标签切换?据我所知,文档方法
public Registration addSelectedChangeListener(
ComponentEventListener<SelectedChangeEvent> listener) {
return addListener(SelectedChangeEvent.class, listener);
}注册监听器,它是在选项卡更改事件之后触发的。
有什么选择吗?
谢谢!
发布于 2022-11-15 12:28:43
如果选项卡内容是导航目标(路由),则可以在窗体视图中使用BeforeLeaveObserver接口:
public class SignupForm extends Div
implements BeforeLeaveObserver {
@Override
public void beforeLeave(BeforeLeaveEvent event) {
if (hasChanges()) {
ContinueNavigationAction action =
event.postpone();
ConfirmDialog confirmDialog = new ConfirmDialog();
confirmDialog.setText("Your form has changes! Are you sure you want to leave?");
confirmDialog.setCancelable(true);
confirmDialog.addConfirmListener(__ -> action.proceed());
confirmDialog.open();
}
}
private boolean hasChanges() {
// TODO: implement your logic to check if there are unsaved changes
}
}https://stackoverflow.com/questions/74433482
复制相似问题