views:

277

answers:

2

I just like to give JSF 2.0 (MyFaces 2.0) a try using Tomcat 6.0. I am completely new to JSF. I just put a static xhtml as test.jsf in the application root. When request the URL, a StackOverflowError will always be thrown:

 java.lang.StackOverflowError
 at org.apache.catalina.core.ApplicationHttpRequest$AttributeNamesEnumerator.<init>(ApplicationHttpRequest.java:904)
 at org.apache.catalina.core.ApplicationHttpRequest.getAttributeNames(ApplicationHttpRequest.java:243)
 at org.apache.catalina.core.ApplicationHttpRequest$AttributeNamesEnumerator.<init>(ApplicationHttpRequest.java:905)
 at org.apache.catalina.core.ApplicationHttpRequest.getAttributeNames(ApplicationHttpRequest.java:243)
 at org.apache.catalina.core.ApplicationHttpRequest$AttributeNamesEnumerator.<init>(ApplicationHttpRequest.java:905)

(repeated many times, but then:)

 at org.apache.catalina.core.ApplicationHttpRequest$AttributeNamesEnumerator.<init>(ApplicationHttpRequest.java:905)
 at org.apache.catalina.core.ApplicationHttpRequest.getAttributeNames(ApplicationHttpRequest.java:243)
 at org.apache.myfaces.context.servlet.RequestMap.getAttributeNames(RequestMap.java:66)
 at org.apache.myfaces.util.AbstractAttributeMap.isEmpty(AbstractAttributeMap.java:100)
 at org.apache.myfaces.renderkit.ErrorPageWriter._writeVariables(ErrorPageWriter.java:558)
 at org.apache.myfaces.renderkit.ErrorPageWriter._writeVariables(ErrorPageWriter.java:538)
 at org.apache.myfaces.renderkit.ErrorPageWriter.debugHtml(ErrorPageWriter.java:259)
 at org.apache.myfaces.renderkit.ErrorPageWriter.debugHtml(ErrorPageWriter.java:221)
 at org.apache.myfaces.renderkit.ErrorPageWriter.handleThrowable(ErrorPageWriter.java:384)
 at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:102)
 at javax.faces.webapp.FacesServlet.service(FacesServlet.java:189)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
 at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:646)
 at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:436)
 at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:374)
 at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:302)
 at org.apache.myfaces.context.servlet.ServletExternalContextImpl.dispatch(ServletExternalContextImpl.java:439)
 at org.apache.myfaces.view.jsp.JspViewDeclarationLanguage.buildView(JspViewDeclarationLanguage.java:115)
 at org.apache.myfaces.lifecycle.RenderResponseExecutor.execute(RenderResponseExecutor.java:103)
 at org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:207)
 at javax.faces.webapp.FacesServlet.service(FacesServlet.java:191)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
 at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:646)
 at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:436)
 at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:374)
 at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:302)
 at org.apache.myfaces.context.servlet.ServletExternalContextImpl.dispatch(ServletExternalContextImpl.java:439)
 at org.apache.myfaces.view.jsp.JspViewDeclarationLanguage.buildView(JspViewDeclarationLanguage.java:115)
 at org.apache.myfaces.lifecycle.RenderResponseExecutor.execute(RenderResponseExecutor.java:103)
 at org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:207)
 at javax.faces.webapp.FacesServlet.service(FacesServlet.java:191)

(also repeated many times...)

What did I made wrong?

+3  A: 

The StackOverflowError during a HTTP servlet request indicates an infinite recursion in the servlet/filter mappings. How is your FacesServlet mapped? It should be mapped to listen on an url-pattern of *.jsf and thus not *.xhtml (which is a common mistake by starters). It will otherwise call itself recursively. The actual files should be named *.xhtml. You just call it as *.jsf in the URL. Please consult/refer the JSF 2.0 books/tutorials/documentation closely how to configure/use JSF properly.

BalusC
thank you, using .xhtml instead of .jsf worked. Why does it call recursivly when its suffixed by .jsf btw?
MRalwasser
Because the *actual* filename would then match the `URL-pattern`. The `FacesServlet` namely internally forwards the request to the actual file which in turn may invoke another servlets/filters listening on the URL in question. In this particular case, the `FacesServlet` itself will be invoked again .. infinite loop!
BalusC
A: 

Thanks a lot BalusC! Made my day! damn recursion :)

somecoder