0

I have web application on spring.I have so form:

<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>

and so handler:

@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";
    }

if I type less 10 symbols result.hasErrors() equals true, but I don't see errors on jsp page( class from model:

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

how to fix it?

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

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

and config:

public class UiConfig {
    @Bean
    public MessageSource messageSource() {
        ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
        messageSource.setBasename("messages");
        return messageSource;
    }
}
Cœur
  • 37,241
  • 25
  • 195
  • 267
Best
  • 1
  • 3
  • 8

1 Answers1

0

I saw it now, you didn't have indicated which is the model attribute for the myCandidate method input.

You have to change

@ModelAttribute @Valid Candidate myCandidate

into

@ModelAttribute("myCandidate") @Valid Candidate myCandidate
araknoid
  • 3,065
  • 5
  • 33
  • 35