下面列出了怎么用com.vaadin.server.DefaultErrorHandler的API类实例代码及写法,或者点击链接到github查看源代码。
@Override
public boolean handle(ErrorEvent event, App app) {
boolean handled = super.handle(event, app);
if (handled && event.getThrowable() != null) {
// Finds the original source of the error/exception
AbstractComponent component = DefaultErrorHandler.findAbstractComponent(event);
if (component != null) {
component.markAsDirty();
}
if (component instanceof Component.Focusable) {
((Component.Focusable) component).focus();
}
}
return handled;
}
@Override
protected void init(VaadinRequest request) {
broadcastReceiverService = AppContextUtil.getSpringBean(BroadcastReceiverService.class);
ServerConfiguration serverConfiguration = AppContextUtil.getSpringBean(ServerConfiguration.class);
if (serverConfiguration.isPush()) {
getPushConfiguration().setPushMode(PushMode.MANUAL);
}
UI.getCurrent().setErrorHandler(new DefaultErrorHandler() {
private static final long serialVersionUID = 1L;
@Override
public void error(com.vaadin.server.ErrorEvent event) {
Throwable e = event.getThrowable();
handleException(request, e);
}
});
setCurrentFragmentUrl(this.getPage().getUriFragment());
setCurrentContext(new UserUIContext());
postSetupApp(request);
EventBusFactory.getInstance().register(new ShellErrorHandler());
mainWindowContainer = new MainWindowContainer();
this.setContent(mainWindowContainer);
getPage().addPopStateListener((Page.PopStateListener) event -> enter(event.getPage().getUriFragment()));
String userAgent = request.getHeader("user-agent");
if (isInNotSupportedBrowserList(userAgent.toLowerCase())) {
NotificationUtil.showWarningNotification(UserUIContext.getMessage(ErrorI18nEnum.BROWSER_OUT_UP_DATE));
}
}
@Override
protected void init(VaadinRequest vaadinRequest) {
HorizontalLayout commandBar = new HorizontalLayout();
commandBar.setWidth("100%");
commandBar.addComponents(issuePanel(), bulkIssuePanel(), redeemPanel());
Grid summary = summaryGrid();
HorizontalLayout statusBar = new HorizontalLayout();
Label statusLabel = new Label("Status");
statusBar.setDefaultComponentAlignment(Alignment.MIDDLE_RIGHT);
statusBar.addComponent(statusLabel);
statusBar.setWidth("100%");
VerticalLayout layout = new VerticalLayout();
layout.addComponents(commandBar, summary, statusBar);
layout.setExpandRatio(summary, 1f);
layout.setSizeFull();
setContent(layout);
UI.getCurrent().setErrorHandler(new DefaultErrorHandler() {
@Override
public void error(com.vaadin.server.ErrorEvent event) {
Throwable cause = event.getThrowable();
log.error("an error occured", cause);
while(cause.getCause() != null) cause = cause.getCause();
Notification.show("Error", cause.getMessage(), Notification.Type.ERROR_MESSAGE);
}
});
setPollInterval(1000);
int offset = Page.getCurrent().getWebBrowser().getTimezoneOffset();
// offset is in milliseconds
ZoneOffset instantOffset = ZoneOffset.ofTotalSeconds(offset/1000);
StatusUpdater statusUpdater = new StatusUpdater(statusLabel, instantOffset);
updaterThread = Executors.newScheduledThreadPool(1).scheduleAtFixedRate(statusUpdater, 1000,
5000, TimeUnit.MILLISECONDS);
setPollInterval(1000);
getSession().getSession().setMaxInactiveInterval(30);
addDetachListener((DetachListener) detachEvent -> {
log.warn("Closing UI");
updaterThread.cancel(true);
});
}