1

I have a simple contact form in my spring project, which is meant to access a backing object, but I get this error

"Neither BindingResult nor plain target object for bean name 'indexBacking' available as request attribute"

My form looks like this:

<form:form action="index.htm" enctype="multipart/form-data" method="post" commandName="indexBacking" accept-charset="UTF-8">
    <form:label path="personName">Name</form:label>
    <form:input id="personName" path="personName" autocomplete="false" /><br />
    <form:label path="personEmail">Email</form:label>
    <form:input id="personEmail" path="personEmail" autocomplete="false" /><br />
    <form:label path="personComments">Your Comments</form:label>
    <form:input id="personComments" path="personComments" autocomplete="false" /><br />
    <input type="submit" alt="Submit"/>
</form:form>

Which is meant to access my controller and save the fields "personName", "personEmail" and "personComments" into my backing object called "indexBacking".

My controller method that I am trying to access is here:

@RequestMapping(value = PAGE_NAME, method = RequestMethod.POST)
public String handleContactForm(ModelMap map, HttpServletRequest request, @ModelAttribute("indexBacking") IndexBacking bo, BindingResult result) {  
    return MODEL_NAME;
}

But I am not sure hot it links with the backing object. Any ideas what I am doing wrong?

Thanks Jon

Jon
  • 3,174
  • 11
  • 39
  • 57

3 Answers3

1

Try using modelAttribute="indexBacking" on form:form instead of commandName="indexBacking".

Also, take a look at this answer; it might have useful information for your case.

Community
  • 1
  • 1
nobeh
  • 9,784
  • 10
  • 49
  • 66
  • Can you post the code snippet the prepares the form and displays on the controller's side? – nobeh Aug 08 '12 at 02:36
  • Isn't that what I posted above? I don't think I have any other related bits of code =P What are you expecting to see? – Jon Aug 08 '12 at 07:50
  • When you need to view the form page what URL do you use? Usually, form processing involves a GET request that prepare the form then display it. Then the second step which is submitting data using POST and then process the result. So based on what you've posted, I do not see the complete cycle. – nobeh Aug 08 '12 at 08:10
  • Silly me! I was being a bit of a numpty (see my answer), thanks for pointing me in the right direction! Sorry for such a late reply. – Jon Aug 29 '12 at 15:47
0

The problem was very simple, I was just being an idiot. I saw a colleague of mine working on a form and assumed a few of his classes were part of Spring as default. All I had to do was handle the received data at the other end properly (by calling the appropriate methods in the controller) and it worked fine.

Thanks for your help chaps - credit to @nobeh for pointing me in the right direction.

Jon
  • 3,174
  • 11
  • 39
  • 57
-1

The problem is in your controller! The following may help you much for your request Check This

user1577291
  • 366
  • 1
  • 3
  • 15
  • That is what I am doing isn't it? My form is directed towards "indexBacking" and I am accepting it into the method within the controller? – Jon Aug 06 '12 at 18:34