Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- NoSuchMessageException: No message found under code 'Size.userForm.username.userForm.username' for locale 'ru_RU
- Required=This field is required.
- Size.userForm.username=Username must be between 8 and 32 characters.
- Duplicate.userForm.username=Such username already exists.
- Size.userForm.password=Password must be over 8 characters.
- Different.userForm.password=Password don't match.
- @Bean
- public MessageSource getMessageSource(){
- ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
- messageSource.setBasename("classpath:validation");
- messageSource.setFallbackToSystemLocale(false);
- return messageSource;
- }
- @Override
- public void validate(Object o, Errors errors) {
- User user = (User) o;
- ValidationUtils.rejectIfEmptyOrWhitespace(errors, "username", "Required");
- if (user.getUsername().length() < 8 || user.getUsername().length() > 32)
- errors.rejectValue("username", "Size.userForm.username");
- if (userService.findByUsername(user.getUsername()) != null)
- errors.rejectValue("username", "Duplicate.userForm.username");
- ValidationUtils.rejectIfEmptyOrWhitespace(errors, "password", "Required");
- if (user.getPassword().length() < 8 || user.getPassword().length() > 32)
- errors.rejectValue("password", "Size.userForm.password");
- if (!user.getConfirmPassword().equals(user.getPassword()))
- errors.rejectValue("confirmPassword", "Different.userForm.password");
- }
- <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
- <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
- <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
- <c:set var="contextPath" value="${pageContext.request.contextPath}"/>
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="utf-8">
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
- <meta name="viewport" content="width=device-width, initial-scale=1">
- <meta name="description" content="">
- <meta name="author" content="">
- <title>Create new account</title>
- <link href="${contextPath}/resources/css/bootstrap.min.css" rel="stylesheet">
- <link href="${contextPath}/resources/css/common.css" rel="stylesheet">
- <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
- <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
- </head>
- <body>
- <div class="container">
- <form:form method="POST" modelAttribute="userForm" class="form-signin">
- <h2 class="form-signin-heading">Create your account</h2>
- <spring:bind path="username">
- <div class="form-group ${status.error ? 'has-error' : ''}">
- <form:input type="text" path="username" class="form-control" placeholder="Username"
- autofocus="true"></form:input>
- <form:errors path="username"></form:errors>
- </div>
- </spring:bind>
- <spring:bind path="password">
- <div class="form-group ${status.error ? 'has-error' : ''}">
- <form:input type="password" path="password" class="form-control" placeholder="Password"></form:input>
- <form:errors path="password"></form:errors>
- </div>
- </spring:bind>
- <spring:bind path="confirmPassword">
- <div class="form-group ${status.error ? 'has-error' : ''}">
- <form:input type="password" path="confirmPassword" class="form-control"
- placeholder="Confirm your password"></form:input>
- <form:errors path="confirmPassword"></form:errors>
- </div>
- </spring:bind>
- <button class="btn btn-lg btn-primary btn-block" type="submit">Submit</button>
- </form:form>
- </div>
- <!-- /container -->
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
- <script src="${contextPath}/resources/js/bootstrap.min.js"></script>
- </body>
Add Comment
Please, Sign In to add comment