protected void focusProblemComponent(ValidationErrors errors) { com.haulmont.cuba.gui.components.Component component = null; if (!errors.getAll().isEmpty()) { component = errors.getFirstComponent(); } if (component != null) { ComponentsHelper.focusComponent(component); } }
@Override protected void postValidate(ValidationErrors errors) { super.postValidate(errors); //remove errors from widget frames errors.getAll().removeIf(error -> !"dashboard$dashboardEditFieldGroup1".equals(error.component.getParent().getId())); List<Widget> dashboardWidgets = dashboardDs.getItem().getWidgets(); Map<String, Long> widgetsCount = dashboardWidgets.stream() .collect(Collectors.groupingBy(Widget::getWidgetId, Collectors.counting())); List<String> nonUniqueIds = widgetsCount.entrySet().stream() .filter(es -> es.getValue() > 1) .map(Map.Entry::getKey) .collect(toList()); if (nonUniqueIds.size() > 0) { errors.add(null, formatMessage("uniqueWidgetId", String.join(",", nonUniqueIds))); } }
/** * Show validation errors alert. Can be overridden in subclasses. * * @param errors the list of validation errors. Caller fills it by errors found during the default validation. */ public void showValidationErrors(ValidationErrors errors) { StringBuilder buffer = new StringBuilder(); for (ValidationErrors.Item error : errors.getAll()) { buffer.append(error.description).append("\n"); } Configuration configuration = AppBeans.get(Configuration.NAME); ClientConfig clientConfig = configuration.getConfig(ClientConfig.class); NotificationType notificationType = NotificationType.valueOf(clientConfig.getValidationNotificationType()); showNotification(messages.getMainMessage("validationFail.caption"), buffer.toString(), notificationType); }
/** * Show validation alert with passed errors and first problem UI component. * * @param origin screen controller * @param errors validation error */ public void showValidationErrors(FrameOwner origin, ValidationErrors errors) { checkNotNullArgument(origin); checkNotNullArgument(errors); if (errors.isEmpty()) { return; } StringBuilder buffer = new StringBuilder(); for (ValidationErrors.Item error : errors.getAll()) { buffer.append(error.description).append("\n"); } ClientConfig clientConfig = configuration.getConfig(ClientConfig.class); String validationNotificationType = clientConfig.getValidationNotificationType(); if (validationNotificationType.endsWith("_HTML")) { // HTML validation notification types are not supported validationNotificationType = validationNotificationType.replace("_HTML", ""); } Notifications notifications = getScreenContext(origin).getNotifications(); notifications.create(NotificationType.valueOf(validationNotificationType)) .withCaption(messages.getMainMessage("validationFail.caption")) .withDescription(buffer.toString()) .show(); focusProblemComponent(errors); }