The JSF 1.2 spec Section 11.3 Specifies that the before and after phase of a Phase Listener must complete.  Thus All Exceptions that occur within the Phase Listener are swallowed.  

Unfortunately this means that neither of the methods at http://wiki.apache.org/myfaces/Handling_Server_Errors works for these types of exceptions.

 

Please See http://forum.java.sun.com/thread.jspa?threadID=662657&messageID=3885082

 

 

What we have done here is Catch the Exception in the Phase Listener and Re-Direct to the Error Page. We have created an Error Handler Class that does that for us.

 

public class AErrorHandler {

           

             private static final Log log = LogFactory.getLog(AErrorHandler.class);

 public static final String ERROR_PAGE="/errorpages/error.jsf";

 

            public static void displayException(FacesContext _facesContext, Exception _ex) {

                        HttpServletResponse response = (HttpServletResponse) _facesContext.getExternalContext().getResponse();

                        HttpServletRequest request = (HttpServletRequest) _facesContext.getExternalContext().getRequest();

                        try {

                                    setPageErrorData(_ex, request);

                                    response.sendRedirect(request.getContextPath()+ERROR_PAGE);

                                    _facesContext.responseComplete();

                                    _ex.printStackTrace();

                        } catch (IOException ex ) {

                                    _ex.printStackTrace();

                                    ex.printStackTrace();

                        }

                        throw new AbortProcessingException("AErrorHandler: displayException() - An Error has occurred.");

            }

           

           

            public static void setPageErrorData(Throwable _e, HttpServletRequest _request) {

                        ErrorData errorData = new ErrorData();

                        errorData.setException(_e);

                        _request.getSession().setAttribute(“errorData”, errorData);

            }

}

 

Where errorData is a request Scoped Backing Bean on our Error Page

             

Tom

 

 

 

 

-----Original Message-----
From: Adam Brod [mailto:[EMAIL PROTECTED]
Sent: Monday, July 10, 2006 12:57 PM
To: MyFaces Discussion
Subject: Re: Send to error page from PhaseListener

 


Thanks for responding.  Unfortunately that doesn't work for PhaseListeners because MyFaces PhaseListenerManager swallows the exception without allowing the Servlet container to redirect to the error page (specified in web.xml).

Perhaps I should log this as an issue in MyFaces?

Adam Brod

Product Development Team

"Cagatay Civici" <[EMAIL PROTECTED]>

07/10/2006 12:51 PM

Please respond to
"MyFaces Discussion" <[email protected]>

To

"MyFaces Discussion" <[email protected]>

cc

 

Subject

Re: Send to error page from PhaseListener

 

 

 




This could help;

http://wiki.apache.org/myfaces/Handling_Server_Errors

Cagatay


On 7/10/06, Adam Brod <[EMAIL PROTECTED]> wrote:

Hi-


I have a PhaseListener that does some business logic.  If there is a RuntimeException, I want to automatically redirect to my error page.  With my PhaseListener, if it throws a RuntimeException, the exception is swallowed and logged in PhaseListenerManager.informPhaseListenersAfter(...).  


What is the best way to redirect all such errors to the error page?  In standard Servlets land, you just declare the exception and the error page in the web.xml file.  That is done once, and it works for the entire web-app.  Is there another way to support this in JSF with PhaseListeners?


Thanks,


Adam Brod

Product Development Team

Disclaimer: This electronic mail and any attachments are confidential and may be privileged. If you are not the intended recipient, please notify the sender immediately by replying to this email, and destroy all copies of this email and any attachments. Thank you.

Disclaimer: This electronic mail and any attachments are confidential and may be privileged. If you are not the intended recipient, please notify the sender immediately by replying to this email, and destroy all copies of this email and any attachments. Thank you.




Reply via email to