Guest User

Untitled

a guest
Mar 24th, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.97 KB | None | 0 0
  1. NoSuchMessageException: No message found under code 'Size.userForm.username.userForm.username' for locale 'ru_RU
  2.  
  3. Required=This field is required.
  4. Size.userForm.username=Username must be between 8 and 32 characters.
  5. Duplicate.userForm.username=Such username already exists.
  6. Size.userForm.password=Password must be over 8 characters.
  7. Different.userForm.password=Password don't match.
  8.  
  9. @Bean
  10. public MessageSource getMessageSource(){
  11. ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
  12. messageSource.setBasename("classpath:validation");
  13. messageSource.setFallbackToSystemLocale(false);
  14. return messageSource;
  15. }
  16.  
  17. @Override
  18. public void validate(Object o, Errors errors) {
  19. User user = (User) o;
  20. ValidationUtils.rejectIfEmptyOrWhitespace(errors, "username", "Required");
  21. if (user.getUsername().length() < 8 || user.getUsername().length() > 32)
  22. errors.rejectValue("username", "Size.userForm.username");
  23. if (userService.findByUsername(user.getUsername()) != null)
  24. errors.rejectValue("username", "Duplicate.userForm.username");
  25. ValidationUtils.rejectIfEmptyOrWhitespace(errors, "password", "Required");
  26. if (user.getPassword().length() < 8 || user.getPassword().length() > 32)
  27. errors.rejectValue("password", "Size.userForm.password");
  28. if (!user.getConfirmPassword().equals(user.getPassword()))
  29. errors.rejectValue("confirmPassword", "Different.userForm.password");
  30. }
  31.  
  32. <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
  33. <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
  34. <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
  35.  
  36. <c:set var="contextPath" value="${pageContext.request.contextPath}"/>
  37.  
  38. <!DOCTYPE html>
  39. <html lang="en">
  40. <head>
  41. <meta charset="utf-8">
  42. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  43. <meta name="viewport" content="width=device-width, initial-scale=1">
  44. <meta name="description" content="">
  45. <meta name="author" content="">
  46.  
  47. <title>Create new account</title>
  48.  
  49. <link href="${contextPath}/resources/css/bootstrap.min.css" rel="stylesheet">
  50. <link href="${contextPath}/resources/css/common.css" rel="stylesheet">
  51.  
  52.  
  53. <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
  54. <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
  55.  
  56. </head>
  57.  
  58. <body>
  59.  
  60. <div class="container">
  61.  
  62. <form:form method="POST" modelAttribute="userForm" class="form-signin">
  63. <h2 class="form-signin-heading">Create your account</h2>
  64. <spring:bind path="username">
  65. <div class="form-group ${status.error ? 'has-error' : ''}">
  66. <form:input type="text" path="username" class="form-control" placeholder="Username"
  67. autofocus="true"></form:input>
  68. <form:errors path="username"></form:errors>
  69. </div>
  70. </spring:bind>
  71.  
  72. <spring:bind path="password">
  73. <div class="form-group ${status.error ? 'has-error' : ''}">
  74. <form:input type="password" path="password" class="form-control" placeholder="Password"></form:input>
  75. <form:errors path="password"></form:errors>
  76. </div>
  77. </spring:bind>
  78.  
  79. <spring:bind path="confirmPassword">
  80. <div class="form-group ${status.error ? 'has-error' : ''}">
  81. <form:input type="password" path="confirmPassword" class="form-control"
  82. placeholder="Confirm your password"></form:input>
  83. <form:errors path="confirmPassword"></form:errors>
  84. </div>
  85. </spring:bind>
  86.  
  87. <button class="btn btn-lg btn-primary btn-block" type="submit">Submit</button>
  88. </form:form>
  89.  
  90. </div>
  91. <!-- /container -->
  92. <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
  93. <script src="${contextPath}/resources/js/bootstrap.min.js"></script>
  94. </body>
Add Comment
Please, Sign In to add comment