[prev in list] [next in list] [prev in thread] [next in thread] 

List:       myfaces-user
Subject:    RE: How do you access public static final values in your JSF app?
From:       <Matt.Rossner-prest () sanofi-aventis ! com>
Date:       2009-11-25 10:08:42
Message-ID: 8DC3B56CA303F24CBD9D4B00350DB9D803A60AFD () GTASMXSUSR01 ! pharma ! aventis ! com
[Download RAW message or body]

I had this exact problem. My solution was to create a managed bean in the application \
scope that implements the Map interface. You need to override the get method and in \
there I use reflection to find the constant field value. Then I store that in an \
actual HashMap (which is declared as final and static in the managed bean), so next \
time it just reads it off the HashMap. Eventually every constant accessed will be in \
the Map and reflection won't be used anymore. I wrote about this on my blog a while \
ago, http://rossner.wordpress.com/

Unfortunately anything on wordpress.com is blocked from my current location so I \
can't give you the permalink address but I think it's the second most recent post \
(haven't posted anything in a while...). I'm wondering if the spring thing works in a \
similar way.

Matt Rossner
Prestataire - Société OnePoint Technology
+33 (1) 41 24 62 66
-----Original Message-----
From: Daniil Barklon [mailto:dbarklon@proship.com] 
Sent: mercredi 25 novembre 2009 00:30
To: MyFaces Discussion
Subject: Re: How do you access public static final values in your JSF app?

If you use Spring, you can use a FieldRetrievingFactoryBean to expose 
your constants as beans.

http://static.springsource.org/spring/docs/2.5.6/api/org/springframework/beans/factory/config/FieldRetrievingFactoryBean.html




Mike Kienenberger wrote:
> More often than not, I use an accessor on the backing bean.
> 
> public String getSomeConstant()
> {
> return SOME_CONSTANT;
> }
> 
> #{someBean.someConstant}
> 
> On Tue, Nov 24, 2009 at 6:07 PM, laredotornado <laredotornado@gmail.com> wrote:
> > Hi,
> > 
> > I'm using MyFaces 1.1.6 and Tomahawk 1.1.9.  I have a public static final
> > int constant in a certain class, and I would like to be able to access that
> > value in my JSF page using JSF code.  I was curious what mechanisms you sue
> > to do that.
> > 
> > The only informative article I found on the subject is here --
> > http://java_rzanner.blogspot.com/2006/09/usage-of-constant-values-in-jsp-code.html,
> >  which discusses creating a map of constants and putting them into the
> > application scope via a ServletContextListener.  If you know of a more
> > straightforward way, please let me know.
> > 
> > Thanks, - Dave
> > 
> > --
> > View this message in context: \
> > http://old.nabble.com/How-do-you-access-public-static-final-values-in-your-JSF-app--tp26504910p26504910.html
> >  Sent from the MyFaces - Users mailing list archive at Nabble.com.
> > 
> > 
> 


-- 
Daniel Barklon

Proship Entertainment, Inc.
Tel:514.485.8823 ext.224
Fax:514.485.2675
Web: http://www.proship.com
980 St. Antoine Street West, Suite #710
Montreal, Quebec, Canada H3C 1A8


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic