Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to pre-populate Spring session bean with Spring MVC annotation

 
Linh Dang Hong
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all, I'm implementing an application that saves Order into database. Obviously, Order has many OrderItems, and I tend to allow user add and remove OrderItems dynmically on screen by using Ajax. I prefer that for each Ajax addOrderItem call, it adds a new OrderItem in an session scoped bean name "order". The problem is, for the Spring Annotation, I cannot find an annotation that maps form bean with an session scoped bean. @ModelAttribute and @SessionAttributes only support form backing bean for the conversation between HTTP GET and HTTP method. Is there any solution to store and map a session bean with the Spring MVC annotation?

Thanks for your kind helps
 
Vinayak Hosamani
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
As far as what I understand from your statement is you need the bean named:"order" to be placed in a session scope, So Instead of using @SessionAttributes you can make use of http-session.
For permanent session attributes, e.g. a user authentication object, use the traditional session.setAttribute method instead.
 
Jayesh A Lalwani
Rancher
Posts: 2756
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You will have to implement a controller that takes OrderItem as input and adds it to the session scoped Order bean.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic