Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to call function upon loading of JSF application

 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ?
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would create a @ManagedBean with @ApplicationScope (or a @Named entity if using CDI/JSR-299) and put your logic in a method annotated with @PostConstruct

This will cause the @PostConstruct annotated method to be invoked immediately after the bean is constructed on JSF application start-up.
 
Author
Posts: 134
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Depending on what you need to do, you may be able to listen for the PostConstructApplicationEvent, otherwise what Lincoln suggested is probably your best bet.
 
Lee Mark
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
here is my faces-config

here is my bean





*/



and my server log when i deploy this app

 
Jason Porter
Author
Posts: 134
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My guess would be you're using the old version of faces-config (and possibly the old jars). The schema you're using for the faces-config is 1.2 change that to the 2.0 version, also double check the jars you're using are the 2.0 jars (look in the MANIFEST.MF file).
 
Lee Mark
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator




i am getting...


 
Lee Mark
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i need to do this in JSF 1.2 only..
is there any way out ?/

Thanks in advance ..

 
Jason Porter
Author
Posts: 134
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're not using 2.0 JSF jars:

INFO: Initializing Mojarra (1.2_10-b01-FCS) for context '/WebApplication14'

Are you using GlassFish v2? If you are there are a couple of options:
1: Upgrade to GlassFish v3
2: bundle the JSF 2.0 jars in your app and turn off class loading delegation and tell it you're bundling JSF in your sun-web.xml:

Probably have to change the dtd to use the correct one.
 
Lee Mark
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i need to do this in JSF 1.2 only..
is there any way out ?/

Thanks in advance ..
 
Jason Porter
Author
Posts: 134
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You've tried putting it in the constructor? You can always grab the FacesContext with FacesContext.getCurrentInstance. If that doesn't work for you, the next thing you've got is a PhaseListener.
 
Lee Mark
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i tried..
but at this time context is not initilized so i am not getting injected properties..


Thanks .
 
Jason Porter
Author
Posts: 134
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try the PhaseListener, maybe someone else has a smarter idea, but with JSF 1.2 that's probably what you'll have to do.
 
Lee Mark
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
nop its not working..
any one has any idea ?
 
Lincoln Baxter
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try a ServletContextListener:

http://www.stardeveloper.com/articles/display.html?article=2001111901&page=1
 
Lee Mark
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yeah..
but i am not getting initilized context at the servletContextListener's context initilized method.
in jSF 1.2 beans having application scope gets initilized when it is needed not at start up //



 
Lincoln Baxter
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You may be able to construct a FacesContext manually if you require it... Or you should consider using a 3rd party Bean scope management system like Weld(CDI) that will provide access to beans at all phases of the Servlet lifecycle (and simplify your faces configuration):

1. http://ocpsoft.com/java/jsf-java/jsf-20-extension-development-accessing-facescontext-in-a-filter/
2. http://seamframework.org/Weld
 
He's dead Jim. Grab his tricorder. I'll get his wallet and this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic