tags:

views:

161

answers:

1

IN JSP i used to put things in bean's constructor which is in APPLCIATION scope, similarly i want to load a function upon deploy of application where i can put .

i tried putting in listener but @ that time i am not getting faces config 's injection .

so is there any way out ?

+1  A: 

Tt sounds suspicious that the listener hadn't worked for you. It should've worked. What I assume has happened is that you expect your request-scoped beans to get their dependencies injected outside a request/response cycle. Well, this won't happen.

So you'd better do one of these:

  • put the @PostConstruct annotation on every bean and initialize it.
  • register a ServletRequestListener which gets triggered on each request

If you want a managed bean to initialize something application-wide (what is that something, btw):

  1. Create a managed bean with scope application
  2. Do your initialization in a method annotated with @PostConstruct

Btw, you have been wrong to put JSP initialization code in constructor. It should've been in the init(..) method. (and actually, shouldn't have been in a JSP at all)

Alternatively you can use a PhaseListener (in the faces-config.xml), where to lazily load tha application settings.

Bozho
i need to do this in JSF 1.2 ,this is not working with 1.2,and i also want initilized context
org.life.java
it works if you use spring ;)
Bozho
yeah but it will break my arch,i have to do this with JSF 1.2 only,bean with application scope gets constructed when its first used.not at deployment time so i am not able to do this using your given 2 optionsis there any thing like listner which listens bean initilization event
org.life.java
what would be the difference actually? Whether it's on deployment or on first access?And as I said - the Servlet Listener is just fine. You are perhaps misusing it.
Bozho
nop.. at deployment time i am not getting fully initilized context on which i need to call method..
org.life.java
what _exactly_ is not initialized?
Bozho
bean with injected peroperties is not getting created..
org.life.java
which bean. in what scope. edit your question adding all the necessary details. I can't help if you remain so vague.
Bozho