Example usage for org.springframework.validation BindingResult getGlobalError

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

Introduction

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

Prototype

@Nullable
ObjectError getGlobalError();

Source Link

Document

Get the first global error, if any.

Usage

From source file:com.zq.fin.seckill.web.BaseController.java

 protected void validate(BindingResult result, Model model){
   ObjectError gloerror = result.getGlobalError();
   List<FieldError> errors= result.getFieldErrors();
      // www .  j av a 2s  .co  m
   if(ObjectUtil.isNotEmpty(gloerror)){
      model.addAttribute("glo", gloerror.getDefaultMessage());
   }
   for(FieldError fieldError:errors){
      model.addAttribute(fieldError.getField(), fieldError.getDefaultMessage());
   }
}

From source file:fr.univrouen.poste.web.admin.UserController.java

@RequestMapping(method = RequestMethod.POST, produces = "text/html")
public String create(@Valid User user, BindingResult result, Model model, HttpServletRequest request) {
    if (result.hasErrors()) {
        model.addAttribute("user", user);
        logger.error("Error when creating an user : " + result.getGlobalError());
        return "admin/users/create";
    }/*from ww  w . ja v a  2  s . co m*/
    if (user.getId() != null) {
        User savedUser = User.findUser(user.getId());
        if (!savedUser.getPassword().equals(user.getPassword())) {
            user.setPassword(messageDigestPasswordEncoder.encodePassword(user.getPassword(), null));
            if (user.getActivationDate() == null) {
                user.setActivationDate(new Date());
            }
        }
    } else {
        user.setPassword(messageDigestPasswordEncoder.encodePassword(user.getPassword(), null));
        if (user.getActivationDate() == null) {
            user.setActivationDate(new Date());
        }
    }
    user.persist();
    return "redirect:/admin/users/" + user.getId().toString();
}

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());/* w  ww  . j  av a 2 s .com*/
    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"));
}

From source file:edu.zipcloud.cloudstreetmarket.core.util.ValidatorUtil.java

public static void raiseFirstError(BindingResult result) {
    if (result.hasFieldErrors()) {
        throw new IllegalArgumentException(result.getFieldError().getDefaultMessage());
    } else if (result.hasGlobalErrors()) {
        throw new IllegalArgumentException(result.getGlobalError().getDefaultMessage());
    } else if (result.hasErrors()) {
        throw new IllegalArgumentException(result.getAllErrors().get(0).getCode());
    }//  w ww  . j av a 2  s  .  c  o m
}