Example usage for org.springframework.validation Errors getFieldErrorCount

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

Introduction

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

Prototype

int getFieldErrorCount(String field);

Source Link

Document

Return the number of errors associated with the given field.

Usage

From source file:jetx.ext.springmvc.SpringMvcFunctions.java

/**
 * ? //from ww w .  j  a v  a2s  . c  o m
 */
public static int countFieldErrors(JetPageContext ctx, String fieldName) {
    Errors errors = FunctionUtils.findErrors(ctx.getContext());
    return errors != null ? errors.getFieldErrorCount(fieldName) : 0;
}

From source file:net.sf.sail.webapp.presentation.validators.GroupParametersValidator.java

/**
 * @see org.springframework.validation.Validator#validate(java.lang.Object, org.springframework.validation.Errors)
 */// w  w w .ja  v  a2 s.c  om
public void validate(Object groupParametersIn, Errors errors) {
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name", "error.groupname.not-specified");
    if (errors.getFieldErrorCount("name") > 0) {
        return;
    }
    GroupParameters groupParameters = (GroupParameters) groupParametersIn;
    if (!StringUtils.isAlphanumeric(groupParameters.getName())) {
        errors.rejectValue("name", "error.groupname.illegal-characters");
    }
    if (groupParameters.getName().length() > MAX_GROUP_NAME_LENGTH) {
        errors.rejectValue("name", "error.groupname.too-long");
    }
    if (groupParameters.getParentId() < 0) {
        errors.rejectValue("parentId", "error.groupparent.must-be-non-negative");
    }
}

From source file:net.sf.sail.webapp.presentation.validators.UserDetailsValidator.java

public void validate(Object userDetailsIn, Errors errors) {
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "password", "error.password.not-specified");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "username", "error.username.not-specified");
    if (errors.getFieldErrorCount("username") > 0) {
        return;/*w  w  w.j  ava 2 s  .  c  om*/
    }
    MutableUserDetails userDetails = (MutableUserDetails) userDetailsIn;
    if (!StringUtils.isAlphanumeric(userDetails.getUsername())) {
        errors.rejectValue("username", "error.username.illegal-characters");
    }
    if (userDetails.getUsername().length() > MAX_USERNAME_LENGTH) {
        errors.rejectValue("username", "error.username.too-long");
    }
    if (errors.hasErrors())
        userDetails.setPassword("");
}

From source file:org.telscenter.sail.webapp.presentation.validators.UserAccountFormValidator.java

/**
 * @see org.springframework.validation.Validator#validate(java.lang.Object, org.springframework.validation.Errors)
 *///from www  . j a  va2 s. co  m
public void validate(Object userAccountFormIn, Errors errors) {
    UserAccountForm userAccountForm = (UserAccountForm) userAccountFormIn;
    MutableUserDetails userDetails = userAccountForm.getUserDetails();

    if (userAccountForm.isNewAccount()) {
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "userDetails.password",
                "error.password-not-specified");

        if (errors.getFieldErrorCount("userDetails.password") > 0) {
            return;
        }

        if (userDetails.getPassword().length() > MAX_PASSWORD_LENGTH) {
            errors.rejectValue("userDetails.password", "error.password-too-long");
            return;
        }

        if (!StringUtils.isAlphanumeric(userDetails.getPassword())) {
            errors.rejectValue("userDetails.password", "error.password-illegal-characters");
            return;
        }

        if (userDetails.getSignupdate() == null) {
            errors.rejectValue("userDetails.signupdate", "error.signupdate-not-specified");
            return;
        }
    } else {
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "userDetails.username",
                "error.username-not-specified");

        if (!StringUtils.isAlphanumeric(userDetails.getUsername())) {
            errors.rejectValue("userDetails.username", "error.illegal-characters");
        }
    }

    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "userDetails.firstname", "error.firstname-not-specified");

    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "userDetails.lastname", "error.lastname-not-specified");

    if (!StringUtils.isAlphanumeric(userDetails.getFirstname())
            || !StringUtils.isAsciiPrintable(userDetails.getFirstname())) {
        errors.rejectValue("userDetails.firstname", "error.firstname-illegal-characters");
        return;
    }

    if (!StringUtils.isAlphanumeric(userDetails.getLastname())
            || !StringUtils.isAsciiPrintable(userDetails.getLastname())) {
        errors.rejectValue("userDetails.lastname", "error.lastname-illegal-characters");
        return;
    }

    if (errors.hasErrors())
        userDetails.setPassword("");
}

From source file:org.telscenter.sail.webapp.presentation.validators.UserDetailsValidator.java

/**
 * @see org.springframework.validation.Validator#validate(java.lang.Object, org.springframework.validation.Errors)
 *//*from   ww  w. j a  v  a 2s  .  c  o m*/
@Override
public void validate(Object userDetailsIn, Errors errors) {
    MutableUserDetails userDetails = (MutableUserDetails) userDetailsIn;

    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "password", "error.password-not-specified");

    if (errors.getFieldErrorCount("password") > 0) {
        return;
    }

    if (userDetails.getPassword().length() > MAX_PASSWORD_LENGTH) {
        errors.rejectValue("password", "error.password-too-long");
        return;
    }

    if (!StringUtils.isAlphanumeric(userDetails.getPassword())) {
        errors.rejectValue("password", "error.password-illegal-characters");
        return;
    }

    if (userDetails.getSignupdate() == null) {
        errors.rejectValue("signupdate", "error.signupdate-not-specified");
        return;
    }

    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "firstname", "error.firstname-not-specified");

    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "lastname", "error.lastname-not-specified");

    if (!StringUtils.isAlphanumeric(userDetails.getFirstname())) {
        errors.rejectValue("firstname", "error.firstname-illegal-characters");
        return;
    }

    if (!StringUtils.isAlphanumeric(userDetails.getLastname())) {
        errors.rejectValue("lastname", "error.lastname-illegal-characters");
        return;
    }

    if (errors.hasErrors())
        userDetails.setPassword("");
}

From source file:org.wise.portal.presentation.validators.UserAccountFormValidator.java

/**
 * @see org.springframework.validation.Validator#validate(java.lang.Object, org.springframework.validation.Errors)
 *//*from w  ww  . jav  a2  s. com*/
public void validate(Object userAccountFormIn, Errors errors) {
    UserAccountForm userAccountForm = (UserAccountForm) userAccountFormIn;
    MutableUserDetails userDetails = userAccountForm.getUserDetails();

    if (userAccountForm.isNewAccount()) {
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "userDetails.password",
                "error.password-not-specified");

        if (errors.getFieldErrorCount("userDetails.password") > 0) {
            return;
        }

        if (userDetails.getPassword().length() > MAX_PASSWORD_LENGTH) {
            errors.rejectValue("userDetails.password", "error.password-too-long");
            return;
        }

        if (!StringUtils.isAlphanumeric(userDetails.getPassword())) {
            errors.rejectValue("userDetails.password",
                    "presentation.validators.ChangePasswordParametersValidator.errorPasswordContainsIllegalCharacters");
            return;
        }

        if (userDetails.getSignupdate() == null) {
            errors.rejectValue("userDetails.signupdate", "error.signupdate-not-specified");
            return;
        }
    } else {
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "userDetails.username",
                "error.username-not-specified");

        if (!StringUtils.isAlphanumeric(userDetails.getUsername())) {
            errors.rejectValue("userDetails.username", "error.username-illegal-characters");
        }
    }

    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "userDetails.firstname", "error.firstname-not-specified");

    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "userDetails.lastname", "error.lastname-not-specified");

    if (!StringUtils.isAlphanumeric(userDetails.getFirstname())
            || !StringUtils.isAsciiPrintable(userDetails.getFirstname())) {
        errors.rejectValue("userDetails.firstname", "error.firstname-illegal-characters");
        return;
    }

    if (!StringUtils.isAlphanumeric(userDetails.getLastname())
            || !StringUtils.isAsciiPrintable(userDetails.getLastname())) {
        errors.rejectValue("userDetails.lastname", "error.lastname-illegal-characters");
        return;
    }

    if (errors.hasErrors())
        userDetails.setPassword("");
}