Example usage for org.springframework.validation ValidationUtils rejectIfEmptyOrWhitespace

List of usage examples for org.springframework.validation ValidationUtils rejectIfEmptyOrWhitespace

Introduction

In this page you can find the example usage for org.springframework.validation ValidationUtils rejectIfEmptyOrWhitespace.

Prototype

public static void rejectIfEmptyOrWhitespace(Errors errors, String field, String errorCode) 

Source Link

Document

Reject the given field with the given error code if the value is empty or just contains whitespace.

Usage

From source file:com.persistent.cloudninja.validator.EditTaskListValidator.java

@Override
public void validate(Object target, Errors errors) {

    EditManageListDTO editManageListDTO = (EditManageListDTO) target;
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "taskList.subject",
            "managetasklist.create.subject.required");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "taskList.startDate",
            "managetasklist.create.startdate.required");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "taskList.dueDate",
            "managetasklist.create.duedate.required");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "taskList.priority",
            "managetasklist.create.priority.required");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "taskList.details",
            "managetasklist.create.details.required");

    if (!DateValidator.isValidDate(editManageListDTO.getTaskList().getStartDate())) {
        errors.rejectValue("taskList.startDate", "Invalid Date", "Format is incorrect");
    } else if (!DateValidator.isValidDate(editManageListDTO.getTaskList().getDueDate())) {
        errors.rejectValue("taskList.dueDate", "Invalid Date", "Format is incorrect");
    } else if (!DateValidator.isValidDateRange(editManageListDTO.getTaskList().getStartDate(),
            editManageListDTO.getTaskList().getDueDate())) {

        errors.rejectValue("taskList.startDate", "Invalid Date",
                "Due Date is incorrect with respect to start date");

    }/*from w w  w .  j a va2  s.  c  om*/
}

From source file:org.tsm.concharto.web.member.SettingsFormValidator.java

public void validate(Object target, Errors errors) {
    SettingsForm settingsForm = (SettingsForm) target;
    //the user can choose to fill out none or all of the password fields
    if (!allPasswordFieldsAreEmpty(settingsForm)) {
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "existingPassword",
                "empty.settingsForm.existingPassword");
        AuthFormValidatorHelper.validateUsernamePasswordFields(settingsForm, errors);
    }//from w w w .j  a v a 2 s .c  o  m
}

From source file:csns.web.validator.MessageValidator.java

@Override
public void validate(Object target, Errors errors) {
    AbstractMessage message = (AbstractMessage) target;

    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "subject", "error.field.required");

    String content = message.getContent();
    if (!StringUtils.hasText(content))
        errors.rejectValue("content", "error.field.required");
    else if (!antiSamy.validate(message.getContent()))
        errors.rejectValue("content", "error.html.invalid");
}

From source file:csns.web.validator.CourseValidator.java

@Override
public void validate(Object target, Errors errors) {
    Course course = (Course) target;//from   www.j  a va 2 s .c o  m

    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name", "error.field.required");

    String code = course.getCode();
    if (!StringUtils.hasText(code))
        errors.rejectValue("code", "error.field.required");
    else if (!Pattern.matches("[A-Z]+\\d+[A-Z]?", code))
        errors.rejectValue("code", "error.course.code.invalid");
    else {
        Course c = courseDao.getCourse(code);
        if (c != null && !c.getId().equals(course.getId()))
            errors.rejectValue("code", "error.course.exists");
    }
}

From source file:csns.web.validator.AssignmentValidator.java

@Override
public void validate(Object target, Errors errors) {
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name", "error.field.required");

    Assignment assignment = (Assignment) target;
    if (!StringUtils.hasText(assignment.getAlias()))
        assignment.setAlias(assignment.getName());

    if (!assignment.isOnline()) {
        errors.pushNestedPath("description");
        ValidationUtils.invokeValidator(resourceValidator, assignment.getDescription(), errors);
        errors.popNestedPath();// w w w .j  a v a 2s  . c o  m
    }
}

From source file:it.f2informatica.core.validator.UpdatePasswordModelValidator.java

@Override
public void validate(Object target, Errors errors) {
    UpdatePasswordModel updatePasswordModel = (UpdatePasswordModel) target;
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "userId", FIELD_MANDATORY);
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "currentPassword", FIELD_MANDATORY);
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "newPassword", FIELD_MANDATORY);
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "passwordConfirmed", FIELD_MANDATORY);
    doFurtherValidation(updatePasswordModel, errors);

}

From source file:csns.web.validator.ResourceValidator.java

@Override
public void validate(Object target, Errors errors) {
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name", "error.field.required");

    Resource resource = (Resource) target;
    if (resource.getType() != ResourceType.NONE) {
        switch (resource.getType()) {
        case TEXT:
            if (!StringUtils.hasText(resource.getText()))
                errors.rejectValue("text", "error.field.required");
            else if (!antiSamy.validate(resource.getText()))
                errors.rejectValue("text", "error.html.invalid");
            break;

        case URL:
            if (!StringUtils.hasText(resource.getUrl()))
                errors.rejectValue("url", "error.field.required");
            break;

        default:/*  www.j a va2 s  . c  o m*/
            // file upload is not validated.
        }
    }
}

From source file:org.jasig.portlet.announcements.model.validators.TopicValidator.java

public void validate(Object obj, Errors errors) {
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "title", "addtopic.title.required.error");

    Topic test = (Topic) obj;//from   ww w. ja v  a2 s. c o  m

    if (test.getSubscriptionMethod() != Topic.PULLED && test.getSubscriptionMethod() != Topic.PUSHED_FORCED
            && test.getSubscriptionMethod() != Topic.PUSHED_INITIAL) {
        errors.rejectValue("subscriptionMethod", "addtopic.subscription.required.error");
    }
}

From source file:csns.web.validator.AddUserValidator.java

@Override
public void validate(Object target, Errors errors) {
    User user = (User) target;//w  w w .  j av  a2 s .  com
    Long id = user.getId();

    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "firstName", "error.field.required");

    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "lastName", "error.field.required");

    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "cin", "error.field.required");

    String cin = user.getCin();
    if (StringUtils.hasText(cin)) {
        User u = userDao.getUserByCin(cin);
        if (u != null && !u.getId().equals(id))
            errors.rejectValue("cin", "error.user.cin.taken");
    }

    String primaryEmail = user.getPrimaryEmail();
    if (StringUtils.hasText(primaryEmail)) {
        User u = userDao.getUserByEmail(primaryEmail);
        if (u != null && !u.getId().equals(id))
            errors.rejectValue("primaryEmail", "error.user.email.taken");
    }
}

From source file:ru.trett.cis.validators.EmployeeValidator.java

public void validate(Object o, Errors errors) {
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "costCenter.number", "not.empty");
    if (!errors.hasErrors()) {
        Employee employee = (Employee) o;
        CostCenter costCenter = inventoryService.getCostCenterByNumber(employee.getCostCenter().getNumber());
        if (costCenter == null)
            errors.rejectValue("costCenter.number", "unknown.costCenter.number");
    }/*  www.j ava2s .  c  om*/
}