users@glassfish.java.net

Re: JSF _at_PostConstruct and exceptions

From: <glassfish_at_javadesktop.org>
Date: Mon, 07 Jul 2008 07:31:36 PDT

I don't believe there is a bug here. The problem is that, under normal circumstances, you don't control when the bean is created. So if the bean is created for the first time during rendering, page content may have already been written to the client, which means the error page content can't be written.

One possible solution is to use the 'beforePhaseListener' attribute which points to a method on some bean with the signature of:

[i]void whatEverYouWantToCallThis(javax.faces.event.PhaseEvent) [/i]

And construct the bean within in the method when the PhaseEvent.getPhaseId() is
PhaseId.RENDER_RESPONSE:

[i]// push the bean to scope if not already available
FacesContext ctx = FacesContext.getCurrentInstance();
ctx.getApplication().evaluteExpressionGet(ctx, "#{managedBeanName}", Object.class); [/i]
[Message sent by forum member 'rlubke' (rlubke)]

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