• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

@Controller annotation query

 
Ranch Hand
Posts: 1376
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I am new to Spring 3.0 and was just running one of the sample code of Spring MVC 3.0.

In sample code , i am using @Controller annotations.As we know that Controller can be Abstract Controller, SimpleFormController, MultiFormController etc.
When i placed @Controller above my POJO class definition (used for MVC operation), how Spring Annotation Handlers is deducing that this POJO class is to be treated as SimpleFormController class? not as MultiFormController class?



 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you mean MultiActionController?
 
Abhay Agarwal
Ranch Hand
Posts: 1376
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes
 
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
NOTE: I changed this first part because I misread the original question

The way you've annotated your controller, it's configured like a SimpleFormController (i.e. one path with separate GET & POST handler methods). The thing that controller annotations do is blur the lines between the old ideas of form controller and multiaction controller. Basically, you can do either or both in the same controller now. Anything you could do with the old SimpleFormController, you can pretty much do with annotations.

If you watch the startup and you've got full logging turned on, you'll see that the annotation handler deduces a lot from the annotations you've got. That's the convention over configuaration showing up. On the other hand, a multi-action controller would look more like the following (using your example) and takes advantage of more explicit path definitions. Notice how it's possible to blend both SimpleFormController behavior with MultiActionController behavior.


 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are there any reasons to use one over the other? I also thought they looked really close to each other at a high level once you could add the annotations, but I don't know enough to understand any real differences, either.
 
Mark Secrist
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

David Newton wrote:Are there any reasons to use one over the other? I also thought they looked really close to each other at a high level once you could add the annotations, but I don't know enough to understand any real differences, either.


Are you asking annoteded vs. extension of SimpleFormController & MulitActionController?
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mmm, more or less. It just seems like with the annotations there's no real need to think about the distinction--but want to know if that's actually true, or if there's other reasons someone might choose one over the other.
 
Mark Secrist
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, it's true that with annotations the distinction becomes blurred. In the past, you had to think about it more explicitly because the behavior was built into the class you extended and you could only extend from one. With annotations, you could make one controller class handle both form processing and other miscellaneous calls that might be considered multi-action. In fact, it's possible to have one controller handle muliple forms if you set it up right - but probably not a good idea.
 
No. No. No. No. Changed my mind. Wanna come down. To see this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic