use of io.jmix.ui.component.ValidationException in project jmix by jmix-framework.
the class BulkEditorWindow method applyChanges.
public void applyChanges() {
if (validateAll()) {
StringBuilder sb = new StringBuilder();
if (modelValidators != null) {
for (Consumer moduleValidator : modelValidators) {
try {
moduleValidator.accept(datasource);
} catch (ValidationException e) {
sb.append(e.getMessage());
sb.append("\n");
}
}
}
if (sb.length() == 0) {
List<String> fields = new ArrayList<>();
for (Map.Entry<String, Field> fieldEntry : dataFields.entrySet()) {
Field field = fieldEntry.getValue();
if (isFieldChanged(field)) {
String localizedName = managedFields.get(fieldEntry.getKey()).getLocalizedName();
fields.add("- " + localizedName);
}
}
if (!fields.isEmpty()) {
showConfirmDialogOrCommit(fields);
} else {
showNotification(messages.getMessage("io.jmix.ui.app.bulk/bulk.noChanges"), NotificationType.HUMANIZED);
}
} else {
showNotification(sb.toString(), NotificationType.TRAY);
}
}
}
use of io.jmix.ui.component.ValidationException in project jmix by jmix-framework.
the class IntegerValidator method validate.
@Override
public void validate(Object value) throws ValidationException {
if (value == null) {
return;
}
boolean result;
if (value instanceof String) {
try {
Datatype<Integer> datatype = Datatypes.getNN(Integer.class);
CurrentAuthentication currentAuthentication = AppBeans.get(CurrentAuthentication.class);
Integer num = datatype.parse((String) value, currentAuthentication.getLocale());
result = checkIntegerOnPositive(num);
} catch (ParseException e) {
result = false;
}
} else {
result = value instanceof Integer && checkIntegerOnPositive((Integer) value);
}
if (!result) {
String msg = message != null ? messageTools.loadString(messagesPack, message) : "Invalid value '%s'";
throw new ValidationException(String.format(msg, value));
}
}
use of io.jmix.ui.component.ValidationException in project jmix by jmix-framework.
the class LongValidator method validate.
@Override
public void validate(Object value) throws ValidationException {
if (value == null) {
return;
}
boolean result;
if (value instanceof String) {
try {
Datatype<Long> datatype = Datatypes.getNN(Long.class);
CurrentAuthentication currentAuthentication = AppBeans.get(CurrentAuthentication.class);
Long num = datatype.parse((String) value, currentAuthentication.getLocale());
result = checkPositive(num);
} catch (ParseException e) {
result = false;
}
} else {
result = value instanceof Long && checkPositive((Long) value);
}
if (!result) {
String msg = message != null ? messageTools.loadString(messagesPack, message) : "Invalid value '%s'";
throw new ValidationException(String.format(msg, value));
}
}
use of io.jmix.ui.component.ValidationException in project jmix by jmix-framework.
the class ScriptValidator method validate.
@Override
public void validate(Object value) throws ValidationException {
Boolean isValid = false;
if (params == null) {
params = new HashMap<>();
}
params.put("value", value);
Map<String, Object> arguments = new HashMap<>();
for (Map.Entry<String, Object> entry : params.entrySet()) {
arguments.put(entry.getKey(), entry.getValue());
}
if (innerScript) {
isValid = (Boolean) scriptEvaluator.evaluate(new StaticScriptSource(script), arguments);
} else if (scriptPath != null) {
isValid = (Boolean) scriptEvaluator.evaluate(new ResourceScriptSource(resources.getResource(scriptPath)), arguments);
}
if (!isValid) {
String msg = message != null ? messageTools.loadString(messagesPack, message) : "Invalid value '%s'";
throw new ValidationException(String.format(msg, value));
}
}
use of io.jmix.ui.component.ValidationException in project jmix by jmix-framework.
the class DateValidator method validate.
@Override
public void validate(Object value) throws ValidationException {
if (value == null)
return;
boolean result;
if (value instanceof String) {
try {
Datatype datatype = Datatypes.getNN(java.sql.Date.class);
CurrentAuthentication currentAuthentication = AppBeans.get(CurrentAuthentication.class);
datatype.parse((String) value, currentAuthentication.getLocale());
result = true;
} catch (ParseException e) {
result = false;
}
} else {
result = value instanceof Date;
}
if (!result) {
String msg = message != null ? messageTools.loadString(messagesPack, message) : "Invalid value '%s'";
throw new ValidationException(String.format(msg, value));
}
}
Aggregations