Example usage for org.springframework.validation Errors hasGlobalErrors

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

Introduction

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

Prototype

boolean hasGlobalErrors();

Source Link

Document

Are there any global errors?

Usage

From source file:org.ualerts.fixed.web.controller.AbstractFormController.java

private List<String> getGlobalErrors(Errors errors) {
    if (!errors.hasGlobalErrors())
        return null;

    List<String> globalErrors = new ArrayList<String>();
    for (ObjectError error : errors.getGlobalErrors()) {
        globalErrors.add(getMessage(error.getCode()));
    }//from w  w  w .ja v  a2s .c om
    return globalErrors;
}

From source file:org.ualerts.fixed.web.controller.AbstractFormController.java

/**
 * Translate the provided errors into a Map that contains global and field
 * level errors//from www  .  j  a  va  2 s. c  om
 * @param errors The errors to be translated
 * @return A Map containing the following:
 *   - "global" => a List of error messages for global-level errors
 *   - "fields" => a Map of field names (String) to errors (List of Strings)
 */
protected Map<String, Object> getMappedErrors(Errors errors) {
    if (!errors.hasErrors())
        return null;

    Map<String, Object> bindErrors = new HashMap<String, Object>();
    if (errors.hasFieldErrors())
        bindErrors.put("fields", getFieldErrors(errors));
    if (errors.hasGlobalErrors())
        bindErrors.put("global", getGlobalErrors(errors));

    return bindErrors;
}

From source file:org.openmrs.web.controller.patient.ShortPatientFormValidatorTest.java

/**
 * @see ShortPatientFormValidator#validate(Object,Errors)
 *//*from  w ww  .  j  ava  2 s . co  m*/
@Test
@Verifies(value = "should fail if all identifiers have been voided", method = "validate(Object,Errors)")
public void validate_shouldFailIfAllIdentifiersHaveBeenVoided() throws Exception {
    Patient p = ps.getPatient(2);
    for (PatientIdentifier pId : p.getActiveIdentifiers())
        pId.setVoided(true);
    ShortPatientModel model = new ShortPatientModel(p);
    Errors errors = new BindException(model, "patientModel");
    validator.validate(model, errors);
    Assert.assertEquals(true, errors.hasGlobalErrors());
}

From source file:org.openmrs.web.controller.patient.ShortPatientFormValidatorTest.java

/**
 * @see ShortPatientFormValidator#validate(Object,Errors)
 *//*w  w  w. j a  v a  2 s  . co m*/
@Test
@Verifies(value = "should fail if all name fields are empty or white space characters", method = "validate(Object,Errors)")
public void validate_shouldFailIfAllNameFieldsAreEmptyOrWhiteSpaceCharacters() throws Exception {
    Patient p = ps.getPatient(2);
    p.getPersonName().setGivenName(" ");
    p.getPersonName().setFamilyName("");
    ShortPatientModel model = new ShortPatientModel(p);
    Errors errors = new BindException(model, "patientModel");
    validator.validate(model, errors);
    Assert.assertEquals(true, errors.hasGlobalErrors());
}

From source file:org.openmrs.web.controller.patient.ShortPatientFormValidatorTest.java

/**
 * @see ShortPatientFormValidator#validate(Object,Errors)
 *///from   www .jav  a 2s. c o m
@Test
@Verifies(value = "should fail if no identifiers are added", method = "validate(Object,Errors)")
public void validate_shouldFailIfNoIdentifiersAreAdded() throws Exception {
    Patient p = ps.getPatient(2);
    List<PatientIdentifier> activeIdentifiers = p.getActiveIdentifiers();
    Set<PatientIdentifier> patientIdentifiers = p.getIdentifiers();
    //remove all the active identifiers
    for (PatientIdentifier activeIdentifier : activeIdentifiers)
        patientIdentifiers.remove(activeIdentifier);

    p.setIdentifiers(patientIdentifiers);
    ShortPatientModel model = new ShortPatientModel(p);
    Errors errors = new BindException(model, "patientModel");
    validator.validate(model, errors);
    Assert.assertEquals(true, errors.hasGlobalErrors());
}