Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Struts 2: ObjectAware actions vs just pulling it out of the session scope

 
Pj Casaro
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I have a jsp that I want to have access to an object in my session map (let's say a user that is logged on) is it better to make a class whose only function is to be a "UserAware" action so that my interceptor can inject the User into it OR can I get away with just getting the user from the session scope in the jsp? Is one better than the other?
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no "better", but that's what the "scope" interceptor is for, isn't it? (I've never really used it.) Otherwise there's a proliferation of interfaces that don't really do very much, and either a proliferation of interceptors, or a single interceptor that has to be updated, that has kind of lame functionality. If I don't have a general-purpose interceptor that does this automatically, and I'm not using Spring session-scoped beans, I'd just implement SessionAware and Preparable. YMMV, depending on your needs and application, though.
 
Pj Casaro
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic