==============================
Problem: Error Trace displayed on UI when there is exception in rendering the view.
==============================
[Reason why stack trace visible:] There is an entry in web.xml which says development = true. Because of this setting the error trace is seen on the UI.
If this param value is set to false then an empty page is shown, which is also not the correct behaviour.
<context-param>
<param-name>facelets.DEVELOPMENT</param-name>
<param-value>true</param-value>
</context-param>
Required behaviour is that the applications forwards the request to the correct error page.
==============================
Solution:
1. Override the FaceletViewHandler.
2. In the method handleRenderException, Forward to error.faces, which is the global error page for the application.
3. Change the view-handler in faces-config.xml to the overridden class.
==============================
===============
Change in Faces-config.xml
===============
<view-handler>com.loginapp.extensions.LoginAppViewHandler</view-handler>
===============
New Class LoginAppViewHandler
to handle the Exceptions when the view is generated.
===============
public class LoginAppViewHandler extends FaceletViewHandler{
@Override
protected void handleRenderException(FacesContext context, Exception ex) throws IOException, ELException,
FacesException {
logger.info("LoginAppViewHandler starts");
try {
logger.error("LoginAppViewHandler Printing the Error ", ex);
HttpServletResponse response = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse();
HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
request.getRequestDispatcher("/error.faces”).forward(request, response);
} catch (Exception ioe) {
logger.error("Could not process redirect to handle application error", ioe);
}
logger.info("LoginAppViewHandler ENDS");
}
}
