FORUM PLAN UPDATE
Date revision: This forum will remain open to new posts and responses until December 1, 2018. (After that date, you will still be able to view and search the forum.) Also, we're taking a second look at the best place to host future conversation. For now, keep using this forum, and stay tuned for more news.



Nov 30, 2011, 11:34 AM
66 Posts

Managed beans LifeCycle annotations @PostConstruct and @PreDestroy

  • Category: Managed Beans in NSF
  • Platform: All
  • Release: 8.5.3
  • Role: Developer
  • Tags:
  • Replies: 1
 Based on the article here http://www.bleedyellow.com/blogs/erik/entry/xpages_are_not_modern?lang=cs_cz  the XPages are based on JSF 1.2  .... what means that we should be able to use annotaions on managed beans to inject the beans lifeCycle.
 
I have found the following information (below) in the docs. But annotations do not work for me in managed beans. I have tried both @PostConstruct and   @PreDestroy but nothing happened. Is there anyone who has experience with this?
 
 
[Life Cycle Annotations]
Starting with JSF 1.2, you can specify managed bean methods that are automat-ically called just after the bean has been constructed and just before the bean 
goes out of scope. This is particularly convenient for beans that establish con-nections to external resources such as databases. 
Annotate the methods with @PostConstruct or @PreDestroy, like this:
 
public class MyBean {
   @PostConstruct
   public void initialize() {
      // initialization code
   }
   @PreDestroy
   public void shutdown() {
      // shutdown code
   }
   // other bean methods
}
These methods will be automatically called, provided the web application is 
deployed in a container that supports the annotations of JSR (Java Specification 
Request) 250 (see http://www.jcp.org/en/jsr/detail?id=250).
 
 
Apr 22, 2017, 3:52 AM
33 Posts
Release 9.0.1 FP8

We are 6 years latter and I am still not able to make it work. Or am I doing anything wrong?

To be clearly understood: @PostConstruct annotation can be used but the method is not called after the bean is constructed.


FORUM PLAN UPDATE
Date revision: This forum will remain open to new posts and responses until December 1, 2018. (After that date, you will still be able to view and search the forum.) Also, we're taking a second look at the best place to host future conversation. For now, keep using this forum, and stay tuned for more news.