Exceptions in @PostConstruct
843844Jul 4 2008 — edited Jul 7 2008Hi,
I'm new to JSF and I've written an example page using facelets and icefaces on glassfish v2 app server. The page contains a number of drop down lists with values stored in a database. I've written an init() method in the JSF bean class that populates the lists used in the dropdowns by calling an EJB to get the data and annotated it with the @PostConstruct annotation. The page works nicely as a quick example but now I'm trying to improve the page by adding exception handling.
What I'm wondering is how to deal with failures in the @PostConstruct method, e.g. if I catch an EJBException? Any method annotated with @PostConstruct cannot throw checked exceptions so I can't do that and add an entry in the web.xml, and if I throw a RuntimeException on catching an EJBException say glassfish errors when it tries to forward onto my error 500 page with the following: "getOutputStream() has already been called for this response".
Is there a better way of prepopulating data in JSF beans where it's possible to forward onto an error page, or is there something else I can do in the @PostConstruct method?
Many thanks in advance,
Darren