Example usage for org.springframework.validation BindingResult getGlobalErrorCount

List of usage examples for org.springframework.validation BindingResult getGlobalErrorCount

Introduction

In this page you can find the example usage for org.springframework.validation BindingResult getGlobalErrorCount.

Prototype

int getGlobalErrorCount();

Source Link

Document

Return the number of global errors.

Usage

From source file:org.jtalks.common.web.dto.ValidationResults.java

/**
 * This method populates global (not related to particular field) errors from the specified {@link BindingResult}
 * to the {@code globalErrors} structure
 *
 * @param bindingResult Binding result to populate global errors from
 *///  w  w w.ja va2  s  .c  om
private void populateGlobalErrors(BindingResult bindingResult) {
    globalErrors = new ArrayList<String>(bindingResult.getGlobalErrorCount());
    for (ObjectError error : bindingResult.getGlobalErrors()) {
        globalErrors.add(error.getDefaultMessage());
    }
}

From source file:fragment.web.RegistrationControllerTest.java

@Test
public void testRegisterPostCaptchaFail() throws Exception {
    MockHttpServletRequest mockRequest = getRequestTemplate(HttpMethod.GET, "/portal/signup");
    mockRequest.setRemoteAddr("1.1.1.1");
    User user = new User("test", "test", "testtest.com", "testuser", VALID_PASSWORD, VALID_PHONE,
            VALID_TIMEZONE, null, null, getRootUser());
    user.setAddress(randomAddress());/*from  w  ww  .  j  a v a  2  s  .  c om*/
    Tenant newTenant = new Tenant("New Co", accountTypeDAO.getDefaultRegistrationAccountType(), null,
            randomAddress(), true, currencyValueService.locateBYCurrencyCode("USD"), null);
    UserRegistration registration = new UserRegistration();
    registration.setCountryList(countryService.getCountries(null, null, null, null, null, null, null));
    registration.setUser((com.citrix.cpbm.access.User) CustomProxy.newInstance(user));
    registration.setTenant((com.citrix.cpbm.access.Tenant) CustomProxy.newInstance(newTenant));
    BindingResult result = new BindException(registration, "registration");
    beforeRegisterCall(mockRequest, registration);
    String view = controller.register(registration, result, "abc", "CAPTCHA_FAIL", map, "1", status,
            mockRequest);
    Assert.assertEquals("register.moreuserinfo", view);
    Assert.assertFalse(status.isComplete());
    Assert.assertTrue(result.hasGlobalErrors());
    Assert.assertTrue(result.getGlobalErrorCount() == 1);
    Assert.assertEquals("errors.registration.captcha", result.getGlobalError().getCode());
    Assert.assertEquals("captcha.error", map.get("registrationError"));
}