Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

@ModelAttribute

 
Shahid Pathan
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic