This week's book / license giveaways are in the JDBC and Relational Databases and Java in General forums.
We're giving away four copies each of PostGIS in Action and Java Advanced Topics Training and have the authors on-line!
See this thread and this one for details.
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


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