Announcement Announcement Module
No announcement yet.
How to bind spring form to annotated method? Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to bind spring form to annotated method?

    I have a bean named for example Breed, it has fields name and color.

    Then in *.jspx I want to insert via spring form new Species to the database:
    <form:form   commandName="breed" path="/breeds" method="POST"> 
            <td> Name: </td>
            <td> <form:input path="name" size="25" maxlength="50" /></td>
            <td> Color: </td>
            <td> <form:input path="color" size="25" maxlength="50" />  </td>
           <td colspan="2">
             <form:input type="submit" value="Add" path="breeds" />
    This form only directs me to the page */breeds without activating any method in controller.
    I have tried several annotations, but no one works, like this:
    @RequestMapping(value = "/breeds", method = RequestMethod.POST)//
        public String handleFormSubmit(@ModelAttribute("breed") Breed newBreed, BindingResult bindingResult,  Model model, HttpServletRequest httpServletRequest) {  
            //add new breed to database
    The Error is
    Neither BindingResult nor plain target object for bean name 'breed' available as request attribute.

    How to write right annotation to the method or why this spring form does not even search for any methods?