What I'm trying to do is cache database data in a bunch of managed beans
at startup. This data rarely changes, so it doesn't make sense to run the
queries again and again. I've seen other people on the list do it this


and although this would work, I have 4 problems with this approach:

1. I have *many* managed beans that need to be init'd, and since I think
you can only have one actionListener per command, I'd need a "container"
or "wrapper" to call each and every init.
2. This init code would have to be sprinkled all over many JSF page (code
bloat; harder to maintain if a change needs to be done)
3. I'd need to write extra logic to prevent these managed beans from being
initialized twice. Although this is easy and small to write, it's
extraneous code. More code = more chance for bugs.
4. Even though I'd have logic in each managed beans to prevent them from
being initialized twice, the init() methods are continually called. This
uses needless CPU cycles.

You might suggest a static block in each and every bean and, while this
would work, it's less than elegant.

Thanks again for any ideas,

"Cagatay Civici" <cagatay.civici@gmail.com>
05/18/2007 10:47 AM
Please respond to
"MyFaces Discussion" <users@myfaces.apache.org>

"MyFaces Discussion" <users@myfaces.apache.org>

Re: how to execute one-time start-up code?

Calling FacesContext.getCurrentInstance() returns null from my own
ServletContextListener.contextInitialized(), even though I've written the
web.xml like so

There won't be any facescontext during startup, it's associated with a
particular request so since there's no request during startup it'll be

Eric what are you trying to do in this listener, I'm sure there's another
way to achieve this without touching FacesContext.




The information contained in this e-mail message is intended only for the
exclusive use of the individual or entity named above and may contain
information that is privileged, confidential or exempt from disclosure
under applicable law. If the reader of this message is not the intended
recipient, or the employee or agent responsible for delivery of the
message to the intended recipient, you are hereby notified that any
dissemination, distribution or copying of this communication is strictly
prohibited. If you have received this communication in error, please
notify the sender immediately by e-mail and delete the material from any
computer. Thank you.

Search Discussions

Discussion Posts


Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 10 of 12 | next ›
Discussion Overview
groupusers @
postedMay 18, '07 at 1:31p
activeMay 18, '07 at 7:15p



site design / logo © 2018 Grokbase