Search in sources :

Example 6 with ValidationException

use of com.haulmont.cuba.gui.components.ValidationException in project cuba by cuba-platform.

the class DesktopDateField method validate.

@Override
public void validate() throws ValidationException {
    if (!isVisible() || !isEditableWithParent() || !isEnabled())
        return;
    try {
        constructDate();
        super.validate();
    } catch (RequiredValueMissingException e) {
        throw e;
    } catch (Exception e) {
        throw new ValidationException(e);
    }
}
Also used : ValidationException(com.haulmont.cuba.gui.components.ValidationException) RequiredValueMissingException(com.haulmont.cuba.gui.components.RequiredValueMissingException) ValidationException(com.haulmont.cuba.gui.components.ValidationException) ParseException(java.text.ParseException) RequiredValueMissingException(com.haulmont.cuba.gui.components.RequiredValueMissingException)

Example 7 with ValidationException

use of com.haulmont.cuba.gui.components.ValidationException in project cuba by cuba-platform.

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);
            UserSessionSource sessionSource = AppBeans.get(UserSessionSource.NAME);
            datatype.parse((String) value, sessionSource.getLocale());
            result = true;
        } catch (ParseException e) {
            result = false;
        }
    } else {
        result = value instanceof Date;
    }
    if (!result) {
        String msg = message != null ? messages.getTools().loadString(messagesPack, message) : "Invalid value '%s'";
        throw new ValidationException(String.format(msg, value));
    }
}
Also used : UserSessionSource(com.haulmont.cuba.core.global.UserSessionSource) ValidationException(com.haulmont.cuba.gui.components.ValidationException) ParseException(java.text.ParseException) Date(java.util.Date) Datatype(com.haulmont.chile.core.datatypes.Datatype)

Example 8 with ValidationException

use of com.haulmont.cuba.gui.components.ValidationException in project cuba by cuba-platform.

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);
    } else {
        params.put("value", value);
    }
    Scripting scripting = AppBeans.get(Scripting.NAME);
    if (innerScript) {
        isValid = scripting.evaluateGroovy(script, params);
    } else if (scriptPath != null) {
        isValid = scripting.runGroovyScript(scriptPath, params);
    }
    if (!isValid) {
        String msg = message != null ? messages.getTools().loadString(messagesPack, message) : "Invalid value '%s'";
        throw new ValidationException(String.format(msg, value));
    }
}
Also used : ValidationException(com.haulmont.cuba.gui.components.ValidationException) Scripting(com.haulmont.cuba.core.global.Scripting)

Aggregations

ValidationException (com.haulmont.cuba.gui.components.ValidationException)8 ParseException (java.text.ParseException)5 UserSessionSource (com.haulmont.cuba.core.global.UserSessionSource)4 Datatype (com.haulmont.chile.core.datatypes.Datatype)1 ServerInfoService (com.haulmont.cuba.core.app.ServerInfoService)1 MessageTools (com.haulmont.cuba.core.global.MessageTools)1 Messages (com.haulmont.cuba.core.global.Messages)1 Scripting (com.haulmont.cuba.core.global.Scripting)1 RequiredValueMissingException (com.haulmont.cuba.gui.components.RequiredValueMissingException)1 BigDecimal (java.math.BigDecimal)1 Date (java.util.Date)1 Matcher (java.util.regex.Matcher)1 CronSequenceGenerator (org.springframework.scheduling.support.CronSequenceGenerator)1