This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Neither BindingResult nor plain target object for bean name 'newAddress'

 
Dharmendra Sharma
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I was working on spring-hibernate based app. Having issue of "Neither BindingResult nor plain target object for bean name 'newAddress' "

The code I have is like below.

Controller code:
------------
@RequestMapping(value="/saveAddress", method=RequestMethod.GET)
public ModelAndView newaddressForm()
{
ModelAndView mav = new ModelAndView("newAddress");
Address address = new Address();
mav.getModelMap().put("newAddress", address);
return mav;
}

@RequestMapping(value="/saveAddress", method=RequestMethod.POST)
public String create(@ModelAttribute("newAddress")Address address, BindingResult result, SessionStatus status)
{
System.out.println("BBBBBBBBBBBBBBB");
validator.validate(address, result);
if (result.hasErrors())
{
return "newAddress";
}
addressDAO.save(address);
status.setComplete();
return "redirect:viewAllAddress.do";
}



Jsp Code:
-----------
<form:form action="saveAddress.do" method="post" commandName="newAddress">


Please someone guide me where I am doing wrong. Help is highly appreciated

Thanks,
Dharmendra Sharma
 
Bill Gorder
Bartender
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where is the rest of your form? Are you actually binding an Address object to it ? Also are you submitting the form with a typical form submit or are you using Ajax or some other means?

Also I would move to the newer modelAttribute tag although command will still work




On a side note this method:



Could be simplified to this:



Or alternatively



It looks a little confusing since you chose to have your view name and model attribute name be the same. But in both cases its the view name being returned.
 
Dharmendra Sharma
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Bill for your advise. The issue resolved. Actually I was not calling the page as per configuration and was not able to resolve the name. Thank you so much for your suggestion again.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic