StackOverflow Exception Upgrading to JSF 2.0Posted by Roger Keays, 3 May 2011, 9:16 AM |
Take a look at the following recursive stack trace which came up whenever I tried to fetch a page after upgrading to JSF 2.0:
javax.faces.webapp.FacesServlet.service(FacesServlet.java:313) com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:546) com.sun.faces.application.view.JspViewHandlingStrategy.executePageToBuildView(JspViewHandlingStrategy.java:363) com.sun.faces.application.view.JspViewHandlingStrategy.buildView(JspViewHandlingStrategy.java:154) com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:100) com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139) javax.faces.webapp.FacesServlet.service(FacesServlet.java:313) com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:546) com.sun.faces.application.view.JspViewHandlingStrategy.executePageToBuildView(JspViewHandlingStrategy.java:363) com.sun.faces.application.view.JspViewHandlingStrategy.buildView(JspViewHandlingStrategy.java:154) com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:100) com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139) javax.faces.webapp.FacesServlet.service(FacesServlet.java:313)
Of course the whole thing eventually blows up into a StackOverflowError. But how did it happen? Even the simplest page gave me the same behaviour.
Well, when I was using JSF 1.2 with Facelets I didn't really get why you should use .jsf in your URLs but .xhtml in your files, so I added the following to my web.xml which allowed me to use .xhtml for both URLs and files.
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.xhtml</param-value>
</context-param>
Now, in JSF 2.0 for some reason this setting only applies to the JSP ViewHandler. So what was happening was the JSP ViewHandler was handling my requests and forwarding them to the appropriate .xhtml resource, which was handle by the JSP ViewHandler which would forward them to yes, the JSP ViewHandler... ad infinitum.
There is an easy fix. You just need to use javax.faces.FACELETS_SUFFIX instead:
<context-param>
<param-name>javax.faces.FACELETS_SUFFIX</param-name>
<param-value>.xhtml</param-value>
</context-param>
| << JSF java.io.FileNotFoundException: Not Found in ExternalContext as a Resource | Back to Blog | JSTL Not Working In JSF 2.0 >> |
Add a comment
Please visit http://www.ninthavenue.com.au/blog/stackoverflow-exception-upgrading-to-jsf-2. to add your comments.