javabean referencing Application variables

T

Todd Peterson

I have a Java timer object that periodically (once a day) gets data
and stores it in an Application attribute of the ServletContext. I am
doing this because there is a substantial amount of data that doesn't
change too frequently, but does change, and I don't want an end user
to experience a significant wait time to get that data every time they
access a page, including the first time.

I have been able to get a JSP page to obtain a handle to the
ServletContext and request that application level data with no
problem. Where things are breaking down for me, is... I would now
like to create a javabean that will be used by JSP pages to perform
some manipulation (filtering, sorting... based on user privs) on that
data.

I'm not thinking it's kosher to access the ServletContext from a
javabean, nor do I know off-hand how to do that... Does anyone have
any recommendations to accomplish, what I hope I've articulated, what
I want to accomplish? I basically want to be able to access
application scoped data from a javabean...

Any help would be greatly appreciated!!!
 
V

VisionSet

Todd Peterson said:
I have a Java timer object that periodically (once a day) gets data
and stores it in an Application attribute of the ServletContext. I am
doing this because there is a substantial amount of data that doesn't
change too frequently, but does change, and I don't want an end user
to experience a significant wait time to get that data every time they
access a page, including the first time.

I have been able to get a JSP page to obtain a handle to the
ServletContext and request that application level data with no
problem. Where things are breaking down for me, is... I would now
like to create a javabean that will be used by JSP pages to perform
some manipulation (filtering, sorting... based on user privs) on that
data.

Don't take this as gospel, I shall learn something here too ;-)

How about creating a class (perhaps a singleton) that can retrieve stuff
from the ServletContext, and make it implement an interface. Your Bean can
then get the singleton of type interface and have no knowledge of the class
it is really dealing with.
Then if you ever need to change where the data comes from, you just make the
new source implement this interface.
 
T

Todd Peterson

VisionSet said:
Don't take this as gospel, I shall learn something here too ;-)

How about creating a class (perhaps a singleton) that can retrieve stuff
from the ServletContext, and make it implement an interface. Your Bean can
then get the singleton of type interface and have no knowledge of the class
it is really dealing with.
Then if you ever need to change where the data comes from, you just make the
new source implement this interface.


Thanks for the suggestion! Being somewhat of a newbie, it took me a
while to come up with an implementation utilizing the strategy you
recommended, but I can now happily say that I've got a fairly elegant
solution (IMHO).

Your response is sincerely appreciated!

Best Regards,
Todd
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,174
Latest member
BlissKetoACV
Top