Redirecting to a Facelet is not working when extending FaceletViewHandler
- by Abel Morelos
I'm overriding the handleRenderResponse method defined in com.sun.facelets.FaceletViewHandler:
protected void handleRenderException(FacesContext context, Exception ex)
I'm overriding this method so I can redirect the user to a custom error page (which contain the desired look and feel and other stuff). This is the way I'm trying to
String errorPage = "/error.xhtml";
String contextPath = context.getExternalContext().getRequestContextPath();
String errorPagePath = contextPath+errorPage;
context.getExternalContext().redirect(errorPagePath);
The previous code is what I'm using to perform the redirect to this custom error page. Anyway, when I perform the redirect I'm prompted with a download dialog (this is with Internet Explorer, in Firefox the page does not display properly or as I would expect). I tried changing "/error.xhtml" to "/error.jsf" but in that case I get a 404 error.
Somehow I think that the XHTML file is not being handled to the Facelets ViewHandler after the redirect, if I open the downloaded xhtml file I can see that the EL expressions were not resolved and the the ui tags were not handled. I don't have problems with other pages in my application, only when doing the redirect programatically.
Important data from my web.xml:
facelets.VIEW_MAPPINGS is set to *.xhtml
javax.faces.DEFAULT_SUFFIX is set to .xhtml
servlet-mapping for the "Faces Servlet" is ".jsf" and "/faces/"