webtier@glassfish.java.net

Re: Where to put one-time executed code on JSF page load

From: <webtier_at_javadesktop.org>
Date: Mon, 15 Mar 2010 05:22:58 PDT

You might try the following approaches:

1. Make the bean view-scoped, so that it doesn't get re-constructed on each postback. (In case you prefer CDI, here's an article on adding the @ViewScoped context to CDI: http://www.verborgh.be/articles/2010/01/06/porting-the-viewscoped-jsf-annotation-to-cdi/)

2. Manually check whether the request is a postback:

[code]
@PostConstruct
public void init() {
    if (!FacesContext.getCurrentInstance().isPostback()) {
        ...do some initialization here...
    }
}
[/code]

There might be other approaches too.

I won't try to assess their merits and drawbacks right now. I only wanted to share what first came to mind.
[Message sent by forum member 'vesuvius' (vesuvius_prime_at_hotmail.com)]

http://forums.java.net/jive/thread.jspa?messageID=391916