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);
}
}
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();
}
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();
}
}
}
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);
}
}
}
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"));
}
}
}
}
Aggregations