Announcement Announcement Module
Collapse
No announcement yet.
How to bind spring form to annotated method? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • 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:
    Code:
    <form:form   commandName="breed" path="/breeds" method="POST"> 
    <table>
         <tr>
            <td> Name: </td>
            <td> <form:input path="name" size="25" maxlength="50" /></td>
        </tr>
        <tr>
            <td> Color: </td>
            <td> <form:input path="color" size="25" maxlength="50" />  </td>
        </tr>
        <tr>
           <td colspan="2">
             <form:input type="submit" value="Add" path="breeds" />
        </tr>
    </table>
    </form:form>
    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:
    Code:
    @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?
Working...
X