File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Spring and the fly likes @ModelAttribute Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "@ModelAttribute" Watch "@ModelAttribute" New topic


Shahid Pathan

Joined: Dec 28, 2010
Posts: 23
I have runnung example with @ModelAttribute in method param as follows

I have just created one more class LoginFormDto as same like LoginForm (you can say duplicate class) and add 2 more method in same controller

When I hit url for dologin1.htm (GET) i am getting following error
java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'loginForm' available as request attribute

Everything work fine for url dologin.htm

I am not getting what exactly i am missing?

Can anyone please point me...
Shahid Pathan

Joined: Dec 28, 2010
Posts: 23
Now I got it why it was not working.
Following is my understanding about the above example.
I did not specified name for ModelAttribute ie(something like @ModelAttribute("loginForm")) . So the container assume name as a Class Name ( first character small)
for example
@ModelAttribute LoginForm => @ModelAttribute("loginForm")

In my second example i used @ModelAttribute LoginFormDto so the container by default looking for
attribute "loginFormDto" not for "loginForm"

If I give explicitly attribute name with ModelAttribute it works without any issue.

I dont know if this is documented somewhere.
Don't get me started about those stupid light bulbs.
subject: @ModelAttribute
jQuery in Action, 3rd edition