aspose file tools*
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 Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "@ModelAttribute" Watch "@ModelAttribute" New topic
Author

@ModelAttribute

Shahid Pathan
Greenhorn

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
Greenhorn

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: @ModelAttribute