Return-Path: Delivered-To: apmail-myfaces-users-archive@www.apache.org Received: (qmail 68153 invoked from network); 18 May 2007 15:10:16 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 18 May 2007 15:10:16 -0000 Received: (qmail 91129 invoked by uid 500); 18 May 2007 15:10:15 -0000 Delivered-To: apmail-myfaces-users-archive@myfaces.apache.org Received: (qmail 91098 invoked by uid 500); 18 May 2007 15:10:15 -0000 Mailing-List: contact users-help@myfaces.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "MyFaces Discussion" Delivered-To: mailing list users@myfaces.apache.org Received: (qmail 91087 invoked by uid 99); 18 May 2007 15:10:15 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 18 May 2007 08:10:15 -0700 X-ASF-Spam-Status: No, hits=2.5 required=10.0 tests=HTML_MESSAGE,NO_REAL_NAME X-Spam-Check-By: apache.org Received-SPF: pass (herse.apache.org: local policy) Received: from [85.158.139.19] (HELO mail178.messagelabs.com) (85.158.139.19) by apache.org (qpsmtpd/0.29) with SMTP; Fri, 18 May 2007 08:10:08 -0700 X-VirusChecked: Checked X-Env-Sender: eric.jung@novartis.com X-Msg-Ref: server-11.tower-178.messagelabs.com!1179500985!606647!1 X-StarScan-Version: 5.5.10.7.1; banners=-,-,- X-Originating-IP: [160.62.1.174] Received: (qmail 5274 invoked from network); 18 May 2007 15:09:45 -0000 Received: from ch2ssaenov01.novartis.com (HELO ch2ssaenov01.novartis.com) (160.62.1.174) by server-11.tower-178.messagelabs.com with AES256-SHA encrypted SMTP; 18 May 2007 15:09:45 -0000 Received: from ch2ssainov01.novartis.net (ch2ssainov01s [192.37.2.174]) by ch2ssaenov01.novartis.com (8.13.6/8.13.6) with ESMTP id l4IF92NN024994 for ; Fri, 18 May 2007 17:09:02 +0200 Received: from phchbs-s3140.EU.novartis.net (phchbs-s3140.eu.novartis.net [192.37.31.248]) by ch2ssainov01.novartis.net (8.13.6/8.13.6) with ESMTP id l4IF9jnx028133 for ; Fri, 18 May 2007 17:09:45 +0200 In-Reply-To: <8c9d4eaa0705180747k1c626948sf3259ea64602202b@mail.gmail.com> To: "MyFaces Discussion" Subject: Re: how to execute one-time start-up code? MIME-Version: 1.0 X-Mailer: Lotus Notes Release 7.0.1 CCH2 May 01, 2006 From: eric.jung@novartis.com Message-ID: Date: Fri, 18 May 2007 11:09:41 -0400 X-MIMETrack: Serialize by Router on CHBSSPH0/PH/Novartis(Release 7.0.1FP1 HF84|October 02, 2006) at 18.05.2007 17:09:45, Serialize complete at 18.05.2007 17:09:45 Content-Type: multipart/alternative; boundary="=_alternative 00534842852572DF_=" X-Virus-Checked: Checked by ClamAV on apache.org This is a multipart message in MIME format. --=_alternative 00534842852572DF_= Content-Type: text/plain; charset="US-ASCII" 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 way: 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, Eric "Cagatay Civici" 05/18/2007 10:47 AM Please respond to "MyFaces Discussion" To "MyFaces Discussion" cc Subject 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 null. Eric what are you trying to do in this listener, I'm sure there's another way to achieve this without touching FacesContext. Cagatay _________________________ CONFIDENTIALITY NOTICE 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. --=_alternative 00534842852572DF_= Content-Type: text/html; charset="US-ASCII"
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 way:

<h:commandLink
  actionListener="#{myManagedBean.init}"
  action="#{foo.bar}">

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,
Eric




"Cagatay Civici" <cagatay.civici@gmail.com>

05/18/2007 10:47 AM
Please respond to
"MyFaces Discussion" <users@myfaces.apache.org>

To
"MyFaces Discussion" <users@myfaces.apache.org>
cc
Subject
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 null.

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

Cagatay



_________________________

CONFIDENTIALITY NOTICE

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.
--=_alternative 00534842852572DF_=--