Return-Path: Delivered-To: apmail-myfaces-users-archive@www.apache.org Received: (qmail 95276 invoked from network); 18 May 2007 16:16:01 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 18 May 2007 16:16:01 -0000 Received: (qmail 84898 invoked by uid 500); 18 May 2007 16:16:04 -0000 Delivered-To: apmail-myfaces-users-archive@myfaces.apache.org Received: (qmail 84857 invoked by uid 500); 18 May 2007 16:16:04 -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 84842 invoked by uid 99); 18 May 2007 16:16:04 -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 09:16:04 -0700 X-ASF-Spam-Status: No, hits=2.0 required=10.0 tests=HTML_MESSAGE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (herse.apache.org: domain of craigmcc@gmail.com designates 72.14.246.250 as permitted sender) Received: from [72.14.246.250] (HELO ag-out-0708.google.com) (72.14.246.250) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 18 May 2007 09:15:57 -0700 Received: by ag-out-0708.google.com with SMTP id 23so972304agd for ; Fri, 18 May 2007 09:15:36 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:sender:to:subject:in-reply-to:mime-version:content-type:references:x-google-sender-auth; b=oiL1ZP5qtt1srLk31+5haDBrYhDMbFFeMHi7/hcuyABBmlXNcuYXajuFCWWKQaDtpJhF89kk3AdiJv+Z+NMdqOkkECr1fZrZbRHT6sYgJbdIOUsoE0zOe5ML+R4DLUsIKN5Fqv606osSFosimYC7Mdxs8xsz4I6+UnvcIBh2hTY= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:sender:to:subject:in-reply-to:mime-version:content-type:references:x-google-sender-auth; b=WjWq60aTM2oRjKVjta12fRXxEALA90Q6eNYt4+FXoxwqrYOGwDcgyNVB4p5YzDuNDLwVFlubbzDHjPFSZO15rjtqRn9UfdnnLpvqopZlbh+T6Fuy96VzHMXd0HeCj7Xvp50dHpLs7l3ZFEez5qe5AVs1P0GwF23cI9piuffu81A= Received: by 10.90.104.14 with SMTP id b14mr1938009agc.1179504935871; Fri, 18 May 2007 09:15:35 -0700 (PDT) Received: by 10.90.91.9 with HTTP; Fri, 18 May 2007 09:15:35 -0700 (PDT) Message-ID: Date: Fri, 18 May 2007 09:15:35 -0700 From: "Craig McClanahan" Sender: craigmcc@gmail.com To: "MyFaces Discussion" Subject: Re: how to execute one-time start-up code? In-Reply-To: MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_122544_8654049.1179504935806" References: <8c9d4eaa0705180632h505e7b69r4bb03fd52544a351@mail.gmail.com> X-Google-Sender-Auth: 9816cd4ac5900907 X-Virus-Checked: Checked by ClamAV on apache.org ------=_Part_122544_8654049.1179504935806 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline On 5/18/07, eric.jung@novartis.com wrote: > > > Hi, > > Calling FacesContext.getCurrentInstance() returns null from my own > ServletContextListener.contextInitialized(), even though I've written the > web.xml like so: > > > > org.apache.myfaces.webapp.StartupServletContextListener > > > > > com.myco.MyServletContextListener > > > > This is using JBoss 4.x. Is there any way to force MyFaces' > ContextListener to execute first? Ordering will not make any difference, because there never will be a FacesContext at initialization time ... that only happens when a request comes in. However, you can still easilhy initialize application scope attributes, because your contextInitialized() method gets a n indirect reference to the ServletContext, so you can just store an attribute there. Once you start processing requests, these attributes will be pre-existing application scope beans. public void contextInitialized(ServletContextEvent event) { ServletContext context = event.getServletContext(); Foo foo = new Foo(...); context.setAttribute("foo", foo); } Craig ------=_Part_122544_8654049.1179504935806 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline

On 5/18/07, eric.jung@novartis.com <eric.jung@novartis.com> wrote:

Hi,

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

        <listener>
                <listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class>
        </listener>
       
        <listener>
                <!-- Our context listener must come AFTER MyFaces's ContextListener -->
                <listener-class>com.myco.MyServletContextListener</listener-class>
        </listener>

This is using JBoss 4.x. Is there any way to force MyFaces' ContextListener to execute first?

Ordering will not make any difference, because there never will be a FacesContext at initialization time ... that only happens when a request comes in.

However, you can still easilhy initialize application scope attributes, because your contextInitialized() method gets a n indirect reference to the ServletContext, so you can just store an attribute there.  Once you start processing requests, these attributes will be pre-existing application scope beans.

    public void contextInitialized(ServletContextEvent event) {
        ServletContext context = event.getServletContext();
        Foo foo = new Foo(...);
        context.setAttribute("foo", foo);
    }

Craig

------=_Part_122544_8654049.1179504935806--