2016-05-06 14 views
0

アプリケーションにHibernate + Spring検証を実装しようとしていますが、問題のあるデータを送信した後にページにエラーメッセージが表示されません。Spring + Hibernate検証エラー

import javax.validation.constraints.NotNull; 
import javax.validation.constraints.Size; 


public class StudentVO { 

private int studentID; 
private String userName; 

@NotNull 
@Size(min=2, max=45, message="Your Name should be between 2 - 45 characters.") 
private String firstName; 

private String middleName; 

@NotNull 
@Size(min=2, max=45, message="Your Surname should be between 2 - 45 characters.") 
private String lastName; 

JSP

<form:form id="myform" modelAttribute="student" method="post" class="form-horizontal" action="/register/registerStudent"> 
<div class="form-group"> 
<label for="firstname" class="col-sm-3 control-label">First Name</label> 
    <div class="col-sm-6"> 
     <form:input type="text" class="form-control float_left" id="firstname" path="firstName" placeholder="First Name" /> 
     <form:errors path="firstName"></form:errors> 
     </div> 
</div> 
    <div class="form-group"> 
    <label for="middlename" class="col-sm-3 control-label" id="md">Middle Name</label> 
     <div class="col-sm-6"> 
      <form:input type="text" class="form-control" id="middlename" path="middleName" placeholder="Middle Name" /> 
     </div> 
</div> 
<div class="form-group"> 
<label for="lastname" class="col-sm-3 control-label">Last Name</label> 
    <div class=" col-sm-6"> 
     <form:input type="text" class="form-control float_left" id="lastname" path="lastName" placeholder="Last Name" required="true" /> 
      <form:errors path="lastName"></form:errors> 
    </div> 

コントローラ

@RequestMapping(value = { "/register/registerStudent" }, method = { RequestMethod.GET, RequestMethod.POST }) 
public String registerSubmit(@Valid StudentVO student, BindingResult result, Model model, HttpServletRequest request, 
     @RequestParam String action, @RequestParam(value = "parentID", required = false) String parentID, 
     @RequestParam(value = "studentID", required = false) String studentID, 
     RedirectAttributes redirectAttributes) { 
    if(result.hasErrors()){ 
     model.addAttribute("student", student); 
     List<Map<String, String>> age = lookupService.getFields("age"); 
     model.addAttribute("age", age); 
     return "studentSignup"; 
    } 
助けを

ありがとう:ここでは、コードです!

@RequestMapping(value = { "/register/registerStudent" }, method = { RequestMethod.GET, RequestMethod.POST }) 
public String registerSubmit(@Valid @ModelAttribute StudentVO student, BindingResult result, Model model, HttpServletRequest request, 
    @RequestParam String action, @RequestParam(value = "parentID", required = false) String parentID, 
    @RequestParam(value = "studentID", required = false) String studentID, 
    RedirectAttributes redirectAttributes) { 
if(result.hasErrors()){ 
    model.addAttribute("student", student); 
    List<Map<String, String>> age = lookupService.getFields("age"); 
    model.addAttribute("age", age); 
    return "studentSignup"; 
} 
+0

春とVerisonを休止: –

+0

クラスパスにBean検証実装がありますか? –

答えて

0

は私が @ModelAttribute言及しなかったので、メソッドのコードは次のようになります私の registerSubmit方法で問題を発見しましたか?
関連する問題