Example usage for org.springframework.validation Errors rejectValue

List of usage examples for org.springframework.validation Errors rejectValue

Introduction

In this page you can find the example usage for org.springframework.validation Errors rejectValue.

Prototype

void rejectValue(@Nullable String field, String errorCode, @Nullable Object[] errorArgs,
        @Nullable String defaultMessage);

Source Link

Document

Register a field error for the specified field of the current object (respecting the current nested path, if any), using the given error description.

Usage

From source file:org.tsm.concharto.web.util.ValidationHelper.java

public static void rejectIfTooLong(Errors errors, String field, int maxLength, String errorCode,
        Object[] errorArgs, String defaultMessage) {
    Object value = errors.getFieldValue(field);

    if (value.toString().length() > maxLength) {
        errors.rejectValue(field, errorCode, errorArgs, defaultMessage);
    }//from   w  ww . java2 s . co  m

}

From source file:com.senfino.yodo.service.AccountServiceImpl.java

private void validateEmail(String email, Errors errors) {
    if (accountDao.findByEmail(email) != null) {
        errors.rejectValue("email", "error.duplicate", new String[] { email }, null);
    }//from w w w . jav  a 2s. c o  m
}

From source file:com.jnj.b2b.storefront.forms.validation.B2BUpdatePwdFormValidator.java

public void isCheckEquals(final UpdatePwdForm form, final Errors errors) {
    if (!form.getPwd().equals(form.getCheckPwd())) {
        errors.rejectValue("checkPwd", "validation.checkPwd.equals", new Object[] {},
                "validation.checkPwd.equals");
    }/*w ww . j av  a 2s . c  o  m*/
}

From source file:es.jffa.tsc.sip04.service.AccountServiceImpl.java

/**
 *
 * @param username//  ww w  .  j a  v a  2  s  .  co  m
 * @param errors
 */
private void _validateUsername(final String username, final Errors errors) {
    if (accountDao.findByUsername(username) != null) {
        errors.rejectValue("username", "error.duplicate", new String[] { username }, null);
    }
}

From source file:net.java.javamoney.examples.tradingapp.web.LogonValidator.java

public void validate(Object obj, Errors errors) {
    Credentials credentials = (Credentials) obj;
    if (credentials == null) {
        errors.rejectValue("username", "error.login.not-specified", null, "Value required.");
    } else {// w  w w  .  j a  v  a  2s  . co m
        logger.info("Validating user credentials for: " + credentials.getUsername() + " @ "
                + credentials.getMarket());
        if (credentials.getUsername().equals("guest") == false) {
            errors.rejectValue("username", "error.login.invalid-user", null, "Incorrect Username.");
        } else {
            if (credentials.getPassword().equals("guest") == false) {
                errors.rejectValue("password", "error.login.invalid-pass", null, "Incorrect Password.");
            }
        }

    }
}

From source file:org.openregistry.core.web.SpringErrorValidationErrorConverter.java

/**
 * Converts the validation errors returned from the {@link org.openregistry.core.service.PersonService} into
 * Spring {@link org.springframework.validation.Errors}.
 *
 * @param validationErrors the errors provided by the {@link org.openregistry.core.service.PersonService}
 * @param errors an instance of Spring's {@link org.springframework.validation.Errors}
 *//*from w w  w. j  a  v  a 2 s.  co  m*/
public void convertValidationErrors(final Set<ConstraintViolation> validationErrors, final Errors errors) {
    for (final ConstraintViolation violation : validationErrors) {
        errors.rejectValue(violation.getPropertyPath().toString(),
                violation.getConstraintDescriptor().getAnnotation().annotationType().getSimpleName(),
                violation.getConstraintDescriptor().getAttributes().values().toArray(), violation.getMessage());
    }
}

From source file:org.mifos.loan.service.LoanDtoValidator.java

public void validate(Object obj, Errors errors) {
    LoanDto loanDto = (LoanDto) obj;//  ww  w  .j  av  a2s. co m
    if (loanDto == null) {
        errors.rejectValue("loanDto", "error.not-specified", null, "error.not-specified");
    } else {
        LOG.info("Validating using LoanDtoValidator");
        if (loanDto.getInterestRate() == null) {
            LOG.info("Found null interest rate-- this should be covered by an annotation based check.");
            return;
        } else {
            if (loanDto.getInterestRate().doubleValue() > loanDto.getLoanProductDto().getMaxInterestRate()) {
                errors.rejectValue("interestRate", "LoanDto.interestRateIsTooHigh",
                        new Object[] { loanDto.getLoanProductDto().getMaxInterestRate() },
                        "LoanDto.interestRateIsTooHigh");
            }
            if (loanDto.getInterestRate().doubleValue() < loanDto.getLoanProductDto().getMinInterestRate()) {
                errors.rejectValue("interestRate", "LoanDto.interestRateIsTooLow",
                        new Object[] { loanDto.getLoanProductDto().getMinInterestRate() },
                        "LoanDto.interestRateIsTooLow");
            }
        }
    }
}

From source file:com.jnj.b2b.storefront.forms.validation.B2BUpdatePasswordFormValidator.java

public void isCheckEquals(final UpdatePasswordForm form, final Errors errors) {
    if (!form.getNewPassword().equals(form.getCheckNewPassword())) {
        errors.rejectValue("checkNewPassword", "validation.checkPwd.equals", new Object[] {},
                "validation.checkPwd.equals");
    }/*from w  w  w .j ava  2s.com*/
}

From source file:com.wisemapping.validator.MapInfoValidator.java

public void validate(Object obj, @NotNull Errors errors) {
    final Mindmap map = (Mindmap) obj;

    if (map == null) {
        errors.rejectValue("map", "error.not-specified", null, "Value required.");
    } else {// www .j  a  v a  2 s  . c o  m

        final String title = map.getTitle();
        final String desc = map.getDescription();
        validateMapInfo(errors, title, desc);
    }

}

From source file:net.sourceforge.subsonic.validator.SavePlaylistValidator.java

public void validate(Object obj, Errors errors) {
    File playlistDirectory = playlistService.getPlaylistDirectory();
    if (!playlistDirectory.exists()) {
        errors.rejectValue("name", "playlist.save.missing_folder", new Object[] { playlistDirectory.getPath() },
                null);/*from   ww  w .ja  va 2  s .c o m*/
    }

    String name = ((SavePlaylistCommand) obj).getName();
    if (name == null || name.trim().length() == 0) {
        errors.rejectValue("name", "playlist.save.noname");
    }
}