Search in sources :

Example 1 with ValidationErrors

use of io.jmix.ui.component.ValidationErrors in project jmix-docs by Haulmont.

the class DemoScreen method onValidateDateBtnClick.

// end::validate-ui[]
// tag::validate-date[]
@Subscribe("validateDateBtn")
public void onValidateDateBtnClick(Button.ClickEvent event) {
    Event demoEvent = metadata.create(Event.class);
    demoEvent.setName("Demo event");
    demoEvent.setStartDate(timeSource.currentTimestamp());
    demoEvent.setEndDate(DateUtils.addDays(demoEvent.getStartDate(), -1));
    ValidationErrors errors = screenValidation.validateCrossFieldRules(this, demoEvent);
    if (!errors.isEmpty()) {
        screenValidation.showValidationErrors(this, errors);
    }
}
Also used : ValidationErrors(io.jmix.ui.component.ValidationErrors) Event(ui.ex1.entity.Event)

Example 2 with ValidationErrors

use of io.jmix.ui.component.ValidationErrors in project jmix by jmix-framework.

the class StandardEditor method commitChanges.

/**
 * Validates screen and commits data context.
 *
 * @return operation result
 */
protected OperationResult commitChanges() {
    ValidationErrors validationErrors = validateScreen();
    if (!validationErrors.isEmpty()) {
        ScreenValidation screenValidation = getApplicationContext().getBean(ScreenValidation.class);
        screenValidation.showValidationErrors(this, validationErrors);
        return OperationResult.fail();
    }
    Runnable standardCommitAction = () -> {
        EntitySet committedEntities = getScreenData().getDataContext().commit();
        InstanceContainer<T> container = getEditedEntityContainer();
        if (container instanceof HasLoader) {
            DataLoader loader = ((HasLoader) container).getLoader();
            if (loader instanceof InstanceLoader) {
                @SuppressWarnings("rawtypes") InstanceLoader instanceLoader = (InstanceLoader) loader;
                if (instanceLoader.getEntityId() == null) {
                    committedEntities.optional(getEditedEntity()).ifPresent(entity -> instanceLoader.setEntityId(EntityValues.getId(entity)));
                }
            }
        }
        fireEvent(AfterCommitChangesEvent.class, new AfterCommitChangesEvent(this));
    };
    BeforeCommitChangesEvent beforeEvent = new BeforeCommitChangesEvent(this, standardCommitAction);
    fireEvent(BeforeCommitChangesEvent.class, beforeEvent);
    if (beforeEvent.isCommitPrevented()) {
        if (beforeEvent.getCommitResult() != null) {
            return beforeEvent.getCommitResult();
        }
        return OperationResult.fail();
    }
    standardCommitAction.run();
    return OperationResult.success();
}
Also used : InMemoryCrudEntityContext(io.jmix.core.accesscontext.InMemoryCrudEntityContext) MetaClass(io.jmix.core.metamodel.model.MetaClass) java.util(java.util) Preconditions(io.jmix.core.common.util.Preconditions) io.jmix.ui.model(io.jmix.ui.model) ValidationErrors(io.jmix.ui.component.ValidationErrors) io.jmix.core(io.jmix.core) Frame(io.jmix.ui.component.Frame) EntityValues(io.jmix.core.entity.EntityValues) Strings(com.google.common.base.Strings) Component(io.jmix.ui.component.Component) Icons(io.jmix.ui.icon.Icons) Action(io.jmix.ui.action.Action) BaseAction(io.jmix.ui.action.BaseAction) Nullable(javax.annotation.Nullable) NotificationType(io.jmix.ui.Notifications.NotificationType) Subscription(io.jmix.core.common.event.Subscription) UnknownOperationResult(io.jmix.ui.util.UnknownOperationResult) UiEntityContext(io.jmix.ui.accesscontext.UiEntityContext) JmixIcon(io.jmix.ui.icon.JmixIcon) Consumer(java.util.function.Consumer) TriggerOnce(io.jmix.core.common.event.TriggerOnce) MetaProperty(io.jmix.core.metamodel.model.MetaProperty) OperationResult(io.jmix.ui.util.OperationResult) UiScreenProperties(io.jmix.ui.UiScreenProperties) ValidationErrors(io.jmix.ui.component.ValidationErrors)

Example 3 with ValidationErrors

use of io.jmix.ui.component.ValidationErrors in project jmix by jmix-framework.

the class PivotTableAggregationEdit method onBeforeCommit.

@Subscribe
protected void onBeforeCommit(BeforeCommitChangesEvent event) {
    if (!event.isCommitPrevented()) {
        PivotTableAggregation aggregation = getEditedEntity();
        boolean hasMatches = existingItems.stream().anyMatch(e -> !Objects.equals(aggregation, e) && Objects.equals(aggregation.getCaption(), e.getCaption()));
        if (hasMatches) {
            ValidationErrors validationErrors = new ValidationErrors();
            validationErrors.add(messages.getMessage(getClass(), "pivotTableEdit.uniqueAggregationOptionCaption"));
            screenValidation.showValidationErrors(this, validationErrors);
            event.preventCommit();
        }
    }
}
Also used : PivotTableAggregation(io.jmix.reports.entity.pivottable.PivotTableAggregation) ValidationErrors(io.jmix.ui.component.ValidationErrors)

Example 4 with ValidationErrors

use of io.jmix.ui.component.ValidationErrors in project jmix by jmix-framework.

the class InputParametersDialog method onPrintReportButtonClick.

@Subscribe("printReportButton")
public void onPrintReportButtonClick(Button.ClickEvent event) {
    if (inputParametersFragment.getReport() != null) {
        ValidationErrors validationErrors = screenValidation.validateUiComponents(getWindow());
        crossValidateParameters(validationErrors);
        if (validationErrors.isEmpty()) {
            ReportTemplate template = inputParametersFragment.getReportTemplate();
            if (template != null) {
                templateCode = template.getCode();
            }
            Report report = inputParametersFragment.getReport();
            Map<String, Object> parameters = inputParametersFragment.collectParameters();
            FluentUiReportRunner fluentRunner = uiReportRunner.byReportEntity(report).withParams(parameters).withTemplateCode(templateCode).withOutputNamePattern(outputFileName).withOutputType(inputParametersFragment.getOutputType()).withParametersDialogShowMode(ParametersDialogShowMode.NO);
            if (inBackground) {
                fluentRunner.inBackground(this);
            }
            if (bulkPrint) {
                fluentRunner.runMultipleReports(inputParameter.getAlias(), selectedEntities);
            } else {
                fluentRunner.runAndShow();
            }
        } else {
            screenValidation.showValidationErrors(this, validationErrors);
        }
    }
}
Also used : FluentUiReportRunner(io.jmix.reportsui.runner.FluentUiReportRunner) ValidationErrors(io.jmix.ui.component.ValidationErrors) Report(io.jmix.reports.entity.Report) ReportTemplate(io.jmix.reports.entity.ReportTemplate)

Example 5 with ValidationErrors

use of io.jmix.ui.component.ValidationErrors in project jmix by jmix-framework.

the class WidgetEdit method validateAdditionalRules.

@Override
protected void validateAdditionalRules(ValidationErrors errors) {
    super.validateAdditionalRules(errors);
    if (errors.isEmpty()) {
        Widget widget = widgetDc.getItem();
        if (widget.getDashboard() != null) {
            List<Widget> dashboardWidgets = widget.getDashboard().getWidgets();
            long cnt = dashboardWidgets.stream().filter(w -> !w.getId().equals(widget.getId()) && w.getWidgetId().equals(widget.getWidgetId())).count();
            if (cnt > 0) {
                errors.add(widgetId, messages.getMessage(WidgetEdit.class, "uniqueWidgetId"));
            }
        }
    }
}
Also used : AccessConstraintsHelper(io.jmix.dashboardsui.dashboard.tools.AccessConstraintsHelper) DataContext(io.jmix.ui.model.DataContext) ValidationErrors(io.jmix.ui.component.ValidationErrors) Autowired(org.springframework.beans.factory.annotation.Autowired) ParamsMap(io.jmix.core.common.util.ParamsMap) HashMap(java.util.HashMap) Widget(io.jmix.dashboards.model.Widget) StringUtils(org.apache.commons.lang3.StringUtils) Messages(io.jmix.core.Messages) Parameter(io.jmix.dashboards.model.parameter.Parameter) WidgetRepository(io.jmix.dashboardsui.repository.WidgetRepository) ParametersFragment(io.jmix.dashboardsui.screen.parameter.ParametersFragment) List(java.util.List) OrderedContainer(io.jmix.ui.component.OrderedContainer) InstanceContainer(io.jmix.ui.model.InstanceContainer) io.jmix.ui.screen(io.jmix.ui.screen) Map(java.util.Map) Fragments(io.jmix.ui.Fragments) Qualifier(org.springframework.beans.factory.annotation.Qualifier) TextField(io.jmix.ui.component.TextField) WidgetTypeInfo(io.jmix.dashboardsui.repository.WidgetTypeInfo) Widget(io.jmix.dashboards.model.Widget)

Aggregations

ValidationErrors (io.jmix.ui.component.ValidationErrors)10 Messages (io.jmix.core.Messages)2 UiScreenProperties (io.jmix.ui.UiScreenProperties)2 Action (io.jmix.ui.action.Action)2 BaseAction (io.jmix.ui.action.BaseAction)2 Icons (io.jmix.ui.icon.Icons)2 Strings (com.google.common.base.Strings)1 io.jmix.core (io.jmix.core)1 InMemoryCrudEntityContext (io.jmix.core.accesscontext.InMemoryCrudEntityContext)1 Subscription (io.jmix.core.common.event.Subscription)1 TriggerOnce (io.jmix.core.common.event.TriggerOnce)1 ParamsMap (io.jmix.core.common.util.ParamsMap)1 Preconditions (io.jmix.core.common.util.Preconditions)1 EntityValues (io.jmix.core.entity.EntityValues)1 MetaClass (io.jmix.core.metamodel.model.MetaClass)1 MetaProperty (io.jmix.core.metamodel.model.MetaProperty)1 Widget (io.jmix.dashboards.model.Widget)1 Parameter (io.jmix.dashboards.model.parameter.Parameter)1 AccessConstraintsHelper (io.jmix.dashboardsui.dashboard.tools.AccessConstraintsHelper)1 WidgetRepository (io.jmix.dashboardsui.repository.WidgetRepository)1