下面列出了怎么用com.vaadin.server.ErrorHandler的API类实例代码及写法,或者点击链接到github查看源代码。
private Button getArtifactDownloadButton(final Table table, final Object itemId) {
final String fileName = (String) table.getContainerDataSource().getItem(itemId)
.getItemProperty(PROVIDED_FILE_NAME).getValue();
final Button downloadIcon = SPUIComponentProvider.getButton(
fileName + "-" + UIComponentIdProvider.ARTIFACT_FILE_DOWNLOAD_ICON, "",
i18n.getMessage(UIMessageIdProvider.TOOLTIP_ARTIFACT_DOWNLOAD), ValoTheme.BUTTON_TINY + " " + "blueicon",
true, FontAwesome.DOWNLOAD, SPUIButtonStyleNoBorder.class);
downloadIcon.setData(itemId);
FileDownloader fileDownloader = new FileDownloader(createStreamResource((Long) itemId));
fileDownloader.extend(downloadIcon);
fileDownloader.setErrorHandler(new ErrorHandler() {
/**
* Error handler for file downloader
*/
private static final long serialVersionUID = 4030230501114422570L;
@Override
public void error(com.vaadin.server.ErrorEvent event) {
uINotification.displayValidationError(i18n.getMessage(UIMessageIdProvider.ARTIFACT_DOWNLOAD_FAILURE_MSG));
}
});
return downloadIcon;
}
/**
* Call the session's {@link ErrorHandler}, if it has one, with the given
* exception wrapped in an {@link ErrorEvent}.
*/
private void callErrorHandler(VaadinSession session, Exception e) {
try {
ErrorHandler errorHandler = ErrorEvent.findErrorHandler(session);
if (errorHandler != null) {
errorHandler.error(new ErrorEvent(e));
}
} catch (Exception ex) {
// Let's not allow error handling to cause trouble; log fails
logger.warn("ErrorHandler call failed", ex);
}
}