Example usage for org.apache.commons.validator GenericValidator isDate

List of usage examples for org.apache.commons.validator GenericValidator isDate

Introduction

In this page you can find the example usage for org.apache.commons.validator GenericValidator isDate.

Prototype

public static boolean isDate(String value, Locale locale) 

Source Link

Document

Checks if the field is a valid date.

Usage

From source file:us.mn.state.health.lims.systemuser.action.UnifiedSystemUserUpdateAction.java

private void validateUser(BaseActionForm dynaForm, ActionMessages errors, boolean loginUserIsNew,
        String loginUserId) {/*from   ww  w.j  a va 2  s  .  c  o m*/
    boolean checkForDuplicateName = loginUserIsNew || userNameChanged(loginUserId, userLoginName);
    // check login name

    if (GenericValidator.isBlankOrNull(userLoginName)) {
        errors.add(ActionErrors.GLOBAL_MESSAGE, new ActionError("errors.loginName.required"));
    } else if (checkForDuplicateName) {
        Login login = loginDAO.getUserProfile(userLoginName);
        if (login != null) {
            errors.add(ActionErrors.GLOBAL_MESSAGE,
                    new ActionError("errors.loginName.duplicated", new StringBuilder(userLoginName)));
        }
    }

    // check first and last name
    if (GenericValidator.isBlankOrNull(dynaForm.getString("userFirstName"))
            || GenericValidator.isBlankOrNull(dynaForm.getString("userLastName"))) {
        errors.add(ActionErrors.GLOBAL_MESSAGE, new ActionError("errors.userName.required"));
    }

    if (passwordUpdated) {
        // check passwords match
        if (GenericValidator.isBlankOrNull(dynaForm.getString("userPassword1"))
                || !dynaForm.getString("userPassword1").equals(dynaForm.getString("userPassword2"))) {
            errors.add(ActionErrors.GLOBAL_MESSAGE, new ActionError("errors.password.match"));
        } else if (!passwordValid(dynaForm.getString("userPassword1"))) { // validity
            errors.add(ActionErrors.GLOBAL_MESSAGE, new ActionError("login.error.password.requirement"));
        }
    }

    // check expiration date
    if (!GenericValidator.isDate(dynaForm.getString("expirationDate"),
            SystemConfiguration.getInstance().getDateLocale())) {
        errors.add(ActionErrors.GLOBAL_MESSAGE,
                new ActionError("errors.date", new StringBuilder(dynaForm.getString("expirationDate"))));
    }

    // check timeout
    if (!timeoutValidAndInRange(dynaForm.getString("timeout"))) {
        errors.add(ActionErrors.GLOBAL_MESSAGE, new ActionError("errors.timeout.range"));
    }
}