Java Code Examples for org.springframework.validation.Errors#hasFieldErrors()

The following examples show how to use org.springframework.validation.Errors#hasFieldErrors() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AdminController.java    From Movie-Ticketing-System-BC-2018.7 with MIT License 6 votes vote down vote up
@RequestMapping(value="/LoginCtrl", method=RequestMethod.POST)
public String login(Model model, HttpSession session,@Valid @ModelAttribute("admin")Admin admin,
		Errors errors)  {
	if (errors.hasFieldErrors()) return "admin/Login";
			
			try {
				 admin= adminSvc.adminLogin(admin.getAdminname(), admin.getPassword());

			} catch (Exception e) {
				errors.reject("", (e instanceof AdminLoginException) ? 
						e.getMessage() : "������Ԥ�ڴ�������ϵ����Ա");
	        	return "admin/Login";
			} 
			session.setAttribute(AdminLoginFilter.ATTR_ADMINUSER, admin);
			return "redirect:./";
}
 
Example 2
Source File: PostsController.java    From blog-spring with MIT License 5 votes vote down vote up
@PostMapping("")
@ResponseBody
public JSONReplyDTO create(@Valid @RequestBody PostForm postForm, Errors errors) {
  if (errors.hasFieldErrors()) {
    FieldError error = errors.getFieldError();
    return JSONReplyDTO.fail(error.getField() + ": " + error.getDefaultMessage());
  }

  postService.create(postForm);

  return JSONReplyDTO.success("Created successfully");
}
 
Example 3
Source File: PostsController.java    From blog-spring with MIT License 5 votes vote down vote up
@PutMapping("/{id}")
@ResponseBody
@Transactional
public JSONReplyDTO update(
    @PathVariable("id") Post post, @Valid @RequestBody PostForm postForm, Errors errors) {
  if (errors.hasFieldErrors()) {
    FieldError error = errors.getFieldError();
    return JSONReplyDTO.fail(error.getField() + ": " + error.getDefaultMessage());
  }

  postService.update(post, postForm);

  return JSONReplyDTO.success("Updated successfully");
}
 
Example 4
Source File: ChangeTestWeightFormValidator.java    From Asqatasun with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void validate(Object target, Errors errors) {
    ChangeTestWeightCommand changeTestWeightCommand = (ChangeTestWeightCommand)target;
    for (Map.Entry<String, String> entry : changeTestWeightCommand.getTestWeightMap().entrySet()) {
        if (!StringUtils.isEmpty(entry.getValue()) && ! weightCheckerPattern.matcher(entry.getValue()).matches()) {
            errors.rejectValue("testWeightMap["+entry.getKey()+"]", WRONG_VALUE_MSG_BUNDLE_KEY);
        }
    }
    if (errors.hasFieldErrors()) {
        errors.rejectValue(GENERAL_ERROR_MSG_KEY,
                WRONG_VALUES_MSG_BUNDLE_KEY);
    }
}
 
Example 5
Source File: Validator.java    From alf.io with GNU General Public License v3.0 5 votes vote down vote up
public static ValidationResult evaluateValidationResult(Errors errors) {
    if (errors.hasFieldErrors()) {
        return ValidationResult.failed(errors.getFieldErrors()
                .stream().map(ValidationResult.ErrorDescriptor::fromFieldError)
                .collect(Collectors.toList()));
    }
    return ValidationResult.success();
}