{"id":14025,"date":"2013-06-13T01:00:54","date_gmt":"2013-06-12T22:00:54","guid":{"rendered":"http:\/\/www.javacodegeeks.com\/?p=14025"},"modified":"2013-06-12T09:12:52","modified_gmt":"2013-06-12T06:12:52","slug":"spring-mvc-validator-and-initbinder","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/2013\/06\/spring-mvc-validator-and-initbinder.html","title":{"rendered":"Spring MVC: Validator and @InitBinder"},"content":{"rendered":"<p>It\u2019s hard to imagine a web-application which doesn\u2019t has some validation logic for an user data. Almost all user\u2019s data has some constraints, e.g. date of birth should consist of day, month, year etc. Spring MVC has its own solution for the data validation, and it\u2019s become available with the help of <strong>Validator interface<\/strong>.<a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/06\/Spring-mvc-validation.png\"><img decoding=\"async\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/06\/Spring-mvc-validation-150x150.png\" alt=\"Spring-mvc-validation\" width=\"150\" height=\"150\" class=\"alignright size-thumbnail wp-image-14112\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/06\/Spring-mvc-validation-150x150.png 150w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/06\/Spring-mvc-validation-200x200.png 200w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/06\/Spring-mvc-validation-100x100.png 100w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/06\/Spring-mvc-validation-42x42.png 42w\" sizes=\"(max-width: 150px) 100vw, 150px\" \/><\/a><\/p>\n<h2>Usage of Spring MVC Validator<\/h2>\n<p>A validation make sense in time when you receive some kind of data from users. An obvious way to do this is to use web forms. The <em>Validator<\/em> interface it is a means to implement the validation logic of entire Spring MVC application. Sounds promising.<\/p>\n<p>There are three things which you need to do in order to start using the Validator:<\/p>\n<ul>\n<li>Create a validator class for some domain model and implment the Validator interface.<\/li>\n<li>Overload supports(Class clazz) method.<\/li>\n<li>Overload validate(Object target, Errors errors) method.<\/li>\n<\/ul>\n<p>Now you know the basics of the <em>Validator<\/em> interface usage. Enough of theory let\u2019s go ahead with practice.<\/p>\n<h2>Exapmle of Vlidator Spring MVC<\/h2>\n<p>I want to demonstrate the <em>Validator<\/em> interface in action on one of my previous tutorials where a validation will not be redundant. I mean the sample application with <a title=\"Spring JPA Data + Hibernate + MySQL + MAVEN\" href=\"http:\/\/fruzenshtein.com\/spring-jpa-data-hibernate-mysql\/\">Spring Data<\/a>. First you need to update the pom.xml file, add the following dependency:<\/p>\n<pre class=\" brush:xml\">...\r\n\t\t&lt;dependency&gt;\r\n\t\t\t&lt;groupid&gt;javax.validation&lt;\/groupid&gt;\r\n\t\t\t&lt;artifactid&gt;validation-api&lt;\/artifactid&gt;\r\n\t\t\t&lt;version&gt;1.0.0.GA&lt;\/version&gt;\r\n\t\t&lt;\/dependency&gt;\r\n\t\t&lt;dependency&gt;\r\n\t\t\t&lt;groupid&gt;org.hibernate&lt;\/groupid&gt;\r\n\t\t\t&lt;artifactid&gt;hibernate-validator&lt;\/artifactid&gt;\r\n\t\t\t&lt;version&gt;4.3.0.Final&lt;\/version&gt;\r\n\t\t&lt;\/dependency&gt;\r\n...\r\n<\/pre>\n<p>In the project I have the one POJO:<\/p>\n<pre class=\" brush:java\">@Entity  \r\n    @Table(name = \"shops\")  \r\n    public class Shop {  \r\n\r\n        @Id  \r\n        @GeneratedValue  \r\n        private Integer id;  \r\n\r\n        private String name;  \r\n\r\n        @Column(name = \"employees_number\")  \r\n        private Integer emplNumber;  \r\n\r\n        public Integer getId() {  \r\n            return id;  \r\n        }  \r\n\r\n        public void setId(Integer id) {  \r\n            this.id = id;  \r\n        }  \r\n\r\n        public String getName() {  \r\n            return name;  \r\n        }  \r\n\r\n        public void setName(String name) {  \r\n            this.name = name;  \r\n        }  \r\n\r\n        public Integer getEmplNumber() {  \r\n            return emplNumber;  \r\n        }  \r\n\r\n        public void setEmplNumber(Integer emplNumber) {  \r\n            this.emplNumber = emplNumber;  \r\n        }  \r\n    }<\/pre>\n<p>So let\u2019s create the validation rules for it:<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<ul>\n<li>The \u201cname\u201d can\u2019t be empty.<\/li>\n<li>The \u201cemplNumber\u201d can\u2019t be empty.<\/li>\n<li>The \u201cemplNumber\u201d can\u2019t be less then 1.<\/li>\n<\/ul>\n<p>The validation class for these purposes will look like:<\/p>\n<pre class=\" brush:java\">import org.springframework.stereotype.Component;\r\nimport org.springframework.validation.Errors;\r\nimport org.springframework.validation.ValidationUtils;\r\nimport org.springframework.validation.Validator;\r\n\r\nimport com.spr.model.Shop;\r\n\r\n@Component\r\npublic class ShopValidator implements Validator {\r\n\r\n\tprivate final static String EMPLOYEES_NUMBER = \"emplNumber\";\r\n\r\n\t@Override\r\n\tpublic boolean supports(Class clazz) {\r\n\t\treturn Shop.class.isAssignableFrom(clazz);\r\n\t}\r\n\r\n\t@Override\r\n\tpublic void validate(Object target, Errors errors) {\r\n\t\tShop shop = (Shop) target;\r\n\r\n\t\tInteger emplNumber = shop.getEmplNumber();\r\n\r\n\t\tValidationUtils.rejectIfEmpty(errors, \"name\", \"shop.name.empty\");\r\n\t\tValidationUtils.rejectIfEmpty(errors, EMPLOYEES_NUMBER, \"shop.emplNumber.empty\");\r\n\r\n\t\tif (emplNumber != null &amp;&amp; emplNumber &lt; 1)\r\n\t\t\terrors.rejectValue(EMPLOYEES_NUMBER, \"shop.emplNumber.lessThenOne\");\r\n\r\n\t}\r\n\r\n}<\/pre>\n<p>Notice that I applied @Component annotation to the class because I&#8217;m planning to inject it later into the ShopController. Here are an explanation of the Validator&#8217;s methods:<\/p>\n<p>supports(Class) &#8211; Can this Validator validate instances of the supplied Class? validate(Object, org.springframework.validation.Errors) &#8211; validates the given object and in case of validation errors, registers those with the given Errors object. For the additional information look at the javadoc of <em>ValidationUtils<\/em> class. The messages which will be shown during validation should be placed in the &#8220;messages.properties&#8221; file:<\/p>\n<pre class=\" brush:bash\">shop.name.empty = The \"Shop name\" field can't be empty.\r\nshop.emplNumber.empty = The \"Employees number\" field can't be empty.\r\nshop.emplNumber.lessThenOne = The number of employees can't be less then 1.<\/pre>\n<p>Let&#8217;s move to the controller&#8217;s code:<\/p>\n<pre class=\" brush:java\">...\r\n\t@Autowired\r\n\tprivate ShopValidator shopValidator;\r\n\r\n\t@InitBinder\r\n\tprivate void initBinder(WebDataBinder binder) {\r\n\t\tbinder.setValidator(shopValidator);\r\n\t}\r\n...\r\n\t@RequestMapping(value=\"\/create\", method=RequestMethod.POST)\r\n\tpublic ModelAndView createNewShop(@ModelAttribute @Valid Shop shop,\r\n\t\t\tBindingResult result,\r\n\t\t\tfinal RedirectAttributes redirectAttributes) {\r\n\r\n\t\tif (result.hasErrors())\r\n\t\t\treturn new ModelAndView(\"shop-new\");\r\n\r\n\t\tModelAndView mav = new ModelAndView();\r\n\t\tString message = \"New shop \"+shop.getName()+\" was successfully created.\";\r\n\r\n\t\tshopService.create(shop);\r\n\t\tmav.setViewName(\"redirect:\/index.html\");\r\n\r\n\t\tredirectAttributes.addFlashAttribute(\"message\", message);\t\r\n\t\treturn mav;\t\t\r\n\t}\r\n...<\/pre>\n<p>The code snippet above demonstrates the main things which you need to perform in a controller layer in order to implement the validation:<\/p>\n<ul>\n<li>Autowiring of the validator.<\/li>\n<li>Adding of the validator to the <strong>InitBinder<\/strong>.<\/li>\n<li>Apply <em>@Valid<\/em> annotation to the model in the concrete controller.<\/li>\n<\/ul>\n<p>And finally let&#8217;s look at the JSP:<\/p>\n<pre class=\" brush:xml\">&lt;%@taglib uri=\"http:\/\/www.springframework.org\/tags\/form\" prefix=\"form\"%&gt;\r\n...\r\n&lt;h1&gt;New Shop page&lt;\/h1&gt;\r\n&lt;form:form method=\"POST\" commandname=\"shop\" action=\"${pageContext.request.contextPath}\/shop\/create.html\"&gt;\r\n&lt;table&gt;\r\n&lt;tbody&gt;\r\n&lt;tr&gt;\r\n&lt;td&gt;Shop name:&lt;\/td&gt;\r\n&lt;td&gt;&lt;form:input path=\"name\"&gt;&lt;\/form:input&gt;&lt;\/td&gt;\r\n&lt;td&gt;&lt;form:errors path=\"name\" cssstyle=\"color: red;\"&gt;&lt;\/form:errors&gt;&lt;\/td&gt;\r\n&lt;\/tr&gt;\r\n&lt;tr&gt;\r\n&lt;td&gt;Employees number:&lt;\/td&gt;\r\n&lt;td&gt;&lt;form:input path=\"emplNumber\"&gt;&lt;\/form:input&gt;&lt;\/td&gt;\r\n&lt;td&gt;&lt;form:errors path=\"emplNumber\" cssstyle=\"color: red;\"&gt;&lt;\/form:errors&gt;&lt;\/td&gt;\r\n&lt;\/tr&gt;\r\n&lt;tr&gt;\r\n&lt;td&gt;&lt;input value=\"Create\" type=\"submit\"&gt;&lt;\/td&gt;\r\n&lt;td&gt;&lt;\/td&gt;\r\n&lt;td&gt;&lt;\/td&gt;\r\n&lt;\/tr&gt;\r\n&lt;\/tbody&gt;\r\n&lt;\/table&gt;\r\n&lt;\/form:form&gt;\r\n...\r\n<\/pre>\n<p>Pay your attention on the form:errors tags, they are responsible for the displaying of the error messages.<\/p>\n<p><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/06\/Spring-MVC-Validator.jpg\"><img decoding=\"async\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/06\/Spring-MVC-Validator-300x90.jpg\" alt=\"Spring-MVC-Validator\" width=\"300\" height=\"90\" class=\"aligncenter size-medium wp-image-14113\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/06\/Spring-MVC-Validator-300x90.jpg 300w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/06\/Spring-MVC-Validator.jpg 569w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<h2>Summary<\/h2>\n<p>The Validator interface allows creation of the flexible validation layer for each domain model object in your application. It&#8217;s a good alternative for the standard JSR-303 validation annotations such as @Min, @Max, @NotNull, @Size etc. You can find the full version of the example on <a title=\"Spring MVC Validator interface\" href=\"https:\/\/github.com\/Fruzenshtein\/spr-data\" target=\"_blank\">GitHub<\/a>.<br \/>\n&nbsp;<\/p>\n<div style=\"border: 1px solid #D8D8D8; background: #FAFAFA; width: 100%; padding-left: 5px;\"><b><i>Reference: <\/i><\/b><a href=\"http:\/\/fruzenshtein.com\/spring-mvc-validator-initbinder\/\">Spring MVC: Validator and @InitBinder<\/a> from our <a href=\"http:\/\/www.javacodegeeks.com\/jcg\">JCG partner<\/a> Alexey Zvolinskiy at the <a href=\"http:\/\/fruzenshtein.com\/\">Fruzenshtein&#8217;s notes<\/a> blog.<\/div>\n","protected":false},"excerpt":{"rendered":"<p>It\u2019s hard to imagine a web-application which doesn\u2019t has some validation logic for an user data. Almost all user\u2019s data has some constraints, e.g. date of birth should consist of day, month, year etc. Spring MVC has its own solution for the data validation, and it\u2019s become available with the help of Validator interface. Usage &hellip;<\/p>\n","protected":false},"author":374,"featured_media":240,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[30,150],"class_list":["post-14025","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-enterprise-java","tag-spring","tag-spring-mvc"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Spring MVC: Validator and @InitBinder<\/title>\n<meta name=\"description\" content=\"It\u2019s hard to imagine a web-application which doesn\u2019t has some validation logic for an user data. Almost all user\u2019s data has some constraints, e.g. date of\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.javacodegeeks.com\/2013\/06\/spring-mvc-validator-and-initbinder.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Spring MVC: Validator and @InitBinder\" \/>\n<meta property=\"og:description\" content=\"It\u2019s hard to imagine a web-application which doesn\u2019t has some validation logic for an user data. Almost all user\u2019s data has some constraints, e.g. date of\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/2013\/06\/spring-mvc-validator-and-initbinder.html\" \/>\n<meta property=\"og:site_name\" content=\"Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2013-06-12T22:00:54+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Alexey Zvolinskiy\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Alexey Zvolinskiy\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/06\\\/spring-mvc-validator-and-initbinder.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/06\\\/spring-mvc-validator-and-initbinder.html\"},\"author\":{\"name\":\"Alexey Zvolinskiy\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/ac87395bf8afb0ae3515feb6a0f36d02\"},\"headline\":\"Spring MVC: Validator and @InitBinder\",\"datePublished\":\"2013-06-12T22:00:54+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/06\\\/spring-mvc-validator-and-initbinder.html\"},\"wordCount\":504,\"commentCount\":6,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/06\\\/spring-mvc-validator-and-initbinder.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"keywords\":[\"Spring\",\"Spring MVC\"],\"articleSection\":[\"Enterprise Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/06\\\/spring-mvc-validator-and-initbinder.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/06\\\/spring-mvc-validator-and-initbinder.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/06\\\/spring-mvc-validator-and-initbinder.html\",\"name\":\"Spring MVC: Validator and @InitBinder\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/06\\\/spring-mvc-validator-and-initbinder.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/06\\\/spring-mvc-validator-and-initbinder.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"datePublished\":\"2013-06-12T22:00:54+00:00\",\"description\":\"It\u2019s hard to imagine a web-application which doesn\u2019t has some validation logic for an user data. Almost all user\u2019s data has some constraints, e.g. date of\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/06\\\/spring-mvc-validator-and-initbinder.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/06\\\/spring-mvc-validator-and-initbinder.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/06\\\/spring-mvc-validator-and-initbinder.html#primaryimage\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"width\":150,\"height\":150,\"caption\":\"spring-interview-questions-answers\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/06\\\/spring-mvc-validator-and-initbinder.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Enterprise Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\\\/enterprise-java\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Spring MVC: Validator and @InitBinder\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Developers Resource Center\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.javacodegeeks.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/javacodegeeks\",\"https:\\\/\\\/x.com\\\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/ac87395bf8afb0ae3515feb6a0f36d02\",\"name\":\"Alexey Zvolinskiy\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/082c897ff3a223afa16dedb5c6638b8b7caef162b241379e9c755b70aed186f5?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/082c897ff3a223afa16dedb5c6638b8b7caef162b241379e9c755b70aed186f5?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/082c897ff3a223afa16dedb5c6638b8b7caef162b241379e9c755b70aed186f5?s=96&d=mm&r=g\",\"caption\":\"Alexey Zvolinskiy\"},\"description\":\"Alexey is a test developer with solid experience in automation of web-applications using Java, TestNG and Selenium. He is so much into QA that even after work he provides training courses for junior QA engineers.\",\"sameAs\":[\"http:\\\/\\\/fruzenshtein.com\\\/\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/alexey-zvolinskiy\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Spring MVC: Validator and @InitBinder","description":"It\u2019s hard to imagine a web-application which doesn\u2019t has some validation logic for an user data. Almost all user\u2019s data has some constraints, e.g. date of","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.javacodegeeks.com\/2013\/06\/spring-mvc-validator-and-initbinder.html","og_locale":"en_US","og_type":"article","og_title":"Spring MVC: Validator and @InitBinder","og_description":"It\u2019s hard to imagine a web-application which doesn\u2019t has some validation logic for an user data. Almost all user\u2019s data has some constraints, e.g. date of","og_url":"https:\/\/www.javacodegeeks.com\/2013\/06\/spring-mvc-validator-and-initbinder.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2013-06-12T22:00:54+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","type":"image\/jpeg"}],"author":"Alexey Zvolinskiy","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Alexey Zvolinskiy","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/2013\/06\/spring-mvc-validator-and-initbinder.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/2013\/06\/spring-mvc-validator-and-initbinder.html"},"author":{"name":"Alexey Zvolinskiy","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/ac87395bf8afb0ae3515feb6a0f36d02"},"headline":"Spring MVC: Validator and @InitBinder","datePublished":"2013-06-12T22:00:54+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2013\/06\/spring-mvc-validator-and-initbinder.html"},"wordCount":504,"commentCount":6,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2013\/06\/spring-mvc-validator-and-initbinder.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","keywords":["Spring","Spring MVC"],"articleSection":["Enterprise Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/2013\/06\/spring-mvc-validator-and-initbinder.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/2013\/06\/spring-mvc-validator-and-initbinder.html","url":"https:\/\/www.javacodegeeks.com\/2013\/06\/spring-mvc-validator-and-initbinder.html","name":"Spring MVC: Validator and @InitBinder","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2013\/06\/spring-mvc-validator-and-initbinder.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2013\/06\/spring-mvc-validator-and-initbinder.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","datePublished":"2013-06-12T22:00:54+00:00","description":"It\u2019s hard to imagine a web-application which doesn\u2019t has some validation logic for an user data. Almost all user\u2019s data has some constraints, e.g. date of","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/2013\/06\/spring-mvc-validator-and-initbinder.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/2013\/06\/spring-mvc-validator-and-initbinder.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/2013\/06\/spring-mvc-validator-and-initbinder.html#primaryimage","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","width":150,"height":150,"caption":"spring-interview-questions-answers"},{"@type":"BreadcrumbList","@id":"https:\/\/www.javacodegeeks.com\/2013\/06\/spring-mvc-validator-and-initbinder.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java","item":"https:\/\/www.javacodegeeks.com\/category\/java"},{"@type":"ListItem","position":3,"name":"Enterprise Java","item":"https:\/\/www.javacodegeeks.com\/category\/java\/enterprise-java"},{"@type":"ListItem","position":4,"name":"Spring MVC: Validator and @InitBinder"}]},{"@type":"WebSite","@id":"https:\/\/www.javacodegeeks.com\/#website","url":"https:\/\/www.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Developers Resource Center","publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/ac87395bf8afb0ae3515feb6a0f36d02","name":"Alexey Zvolinskiy","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/082c897ff3a223afa16dedb5c6638b8b7caef162b241379e9c755b70aed186f5?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/082c897ff3a223afa16dedb5c6638b8b7caef162b241379e9c755b70aed186f5?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/082c897ff3a223afa16dedb5c6638b8b7caef162b241379e9c755b70aed186f5?s=96&d=mm&r=g","caption":"Alexey Zvolinskiy"},"description":"Alexey is a test developer with solid experience in automation of web-applications using Java, TestNG and Selenium. He is so much into QA that even after work he provides training courses for junior QA engineers.","sameAs":["http:\/\/fruzenshtein.com\/"],"url":"https:\/\/www.javacodegeeks.com\/author\/alexey-zvolinskiy"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/14025","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/users\/374"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=14025"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/14025\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media\/240"}],"wp:attachment":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=14025"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=14025"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=14025"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}