JSF application Deployment time function call
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 ou开发者_如何学运维t ?
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):
- Create a managed bean with scope
application
- 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.
精彩评论