2013-08-28 55 views
0

我已經在spring.I web應用程序具有這樣的形式:彈簧形式不顯示錯誤消息

<form:form action="submitFormAdd" id="formId" method="GET" modelAttribute="myCandidate"> 
<label for="nameInput" path="name"> Name</label> 
<form:input path="name" id="nameInput"></form:input> 
<form:errors path="name" cssclass="error"></form:errors> 
</form:form> 

等處理程序:

@RequestMapping("/submitFormAdd") 
    public String submitFormAdd(Model model 
      ,@ModelAttribute @Valid Candidate myCandidate 
      ,BindingResult result 
      ,@ModelAttribute("skillsIdList") Set<Skill> skills 
      ,@ModelAttribute("vacanciesForCandidate") Set<Vacancy> vacanciesForCandidate){ 
     if(result.hasErrors()) { 
       return "candidateDetailsAdd"; 
      } 
     return "candidateMenu"; 
    } 

如果I型少10個符號result.hasErrors ()等於真實的,但我沒有看到JSP網頁上有錯誤(從模型 類:

public class Candidate { 
    @Size(min=10) 
    private String name; 
    //getters and setters 
} 

如何解決我T'

P.S. 屬性(/ui/src/main/resources/messages.properties):

Size.myCandidate.name = more size please 
NotNull = Field cannot be left blank 
NotEmpty = not empty 

和配置:

public class UiConfig { 
    @Bean 
    public MessageSource messageSource() { 
     ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource(); 
     messageSource.setBasename("messages"); 
     return messageSource; 
    } 
} 
+0

的[春季3表單驗證顯示錯誤信息,但不顯示字段名稱]可能重複(http://stackoverflow.com/questions/ 16105282/spring-3-form-validation-shows-error-messages-but-field-name-not-displayed) – araknoid

+0

我會讀它,thx – Best

+0

不是100%確定,但似乎你缺少message-file.properties用於錯誤驗證和正確配置。 – araknoid

回答

0

我看到現在,你沒有表明這是模型屬性爲myCandidate方法輸入。

你必須改變

@ModelAttribute @Valid Candidate myCandidate 

@ModelAttribute("myCandidate") @Valid Candidate myCandidate 
+0

它的作品但我不明白differencies – Best