Created
September 17, 2012 09:46
-
-
Save benelog/3736481 to your computer and use it in GitHub Desktop.
Spring validation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RequestMapping("/saveBoard") | |
public String saveBoard(@ModelAttribute @Valid Board board, BindingResult binding) { | |
if (binding.hasErrors()) { | |
return "boardInputForm"; | |
} | |
Integer seq = service.save(board); | |
return "redirect:boardDetail/" + seq; | |
} | |
@InitBinder | |
protected void initBinder(WebDataBinder binder) { | |
binder.setValidator(new BoardValidator()); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<dependency> | |
<groupId>javax.validation</groupId> | |
<artifactId>validation-api</artifactId> | |
<version>1.0.0.GA</version> | |
</dependency> | |
<dependency> | |
<groupId>org.hibernate</groupId> | |
<artifactId>hibernate-validator-annotation-processor</artifactId> | |
<version>4.1.0.Final</version> | |
</dependency> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="alert alert-error" th:if="${#fields.hasErrors('title')}" th:text="${#fields.errors('title')}"> | |
title is empty | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment