• 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
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

get applicationContext at Business layer

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would like to get and set a session value that would be available through out the application.as request variables wouldnot be available in business layer would there be an option
to do this? something like getting webapplicationcontext and setting session values.

i know this is a dirty fix and session variables should not be passed beyond presentation layer but would still like to know a way to do this.
 
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You might set value in ThreadLocal and the get the same in business layer.
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, I get the web related data in my Controller and just pass them as parameters to my Service business layer classes.

Mark
 
kv ruby
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Piyush Mangal wrote:You might set value in ThreadLocal and the get the same in business layer.




That seems to be a solution.Thankyou would investigate more about it.
 
kv ruby
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mark Spritzler wrote:Well, I get the web related data in my Controller and just pass them as parameters to my Service business layer classes.

Mark



Ideally this is the solution but that would introduce lot of code change in our case so trying a dirty fix.
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeah, something like ThreadLocal helps stop api changes. I used it to put my PageRequest object into ThreadLocal so I wasn't passing pagination information through my layers api parameters. Instead the Controller layer would create the PageRequest object and put it into ThreadLocal. Then all the way down in my Repository layer I get the PageRequest out of ThreadLocal so I can pass it to my query string. Well, I actually get it from ThreadLocal in my Service layer because I have no Repository code, just Repository interfaces because I am using Spring Data.

Mark
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic