Reputation: 21
As soon as I try to open my index.xhtml via "http: //localhost:8080/beginner/faces/index.jsf" I'll get the following exception:
javax.servlet.ServletException
javax.faces.webapp.FacesServlet.service(FacesServlet.java:606)
org.jboss.weld.servlet.ConversationPropagationFilter.doFilter(ConversationPropagationFilter.java:62)
java.lang.NullPointerException
com.sun.faces.renderkit.RenderKitImpl.createResponseWriter(RenderKitImpl.java:228)
com.sun.faces.application.view.JspViewHandlingStrategy.renderView(JspViewHandlingStrategy.java:214)
com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:125)
javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:288)
com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121)
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:594)
org.jboss.weld.servlet.ConversationPropagationFilter.doFilter(ConversationPropagationFilter.java:62)
note The full stack trace of the root cause is available in the JBoss Web/7.0.13.Final logs.
In eclipse I created a Maven Project via the "new Maven project wizard" and chose Group Id: "org.jboss.spec.archetypes", Artifact Id "jboss-javaee6-webapp-blank-archetype" version: 7.13 I'm using JBoss 7.1.1.FINAL and tried JDK 6 and JDK7
the index.xthml looks like this:
<?xml version="1.0" encoding= "UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html">
<h:head>
<title>First JSF</title>
</h:head>
<h:body>
<h1>Hello there</h1>
</h:body>
</html>
Im looking for hours for a reason, but cant find any solution, even though I did every step that this workshop-book told me to do.
Upvotes: 2
Views: 1984
Reputation: 1108722
Is it really a XHTML (Facelets) file?
Look closer at the classname in the following line of the stack trace to learn who's handling the view:
com.sun.faces.application.view.JspViewHandlingStrategy.renderView(JspViewHandlingStrategy.java:214)
Hey, it's being treated as a JSP file! Something's definitely not entirely right here. One would expect a FaceletViewHandlingStrategy
here if it was really treated as a Facelets file.
Let's look back at the URL:
http://localhost:8080/beginner/faces/index.jsf
Huh? It contains 2 (two!) typical FacesServlet
URL mapping patterns! The /faces/*
and *.jsf
. Big chance that it caused some confusion in JSF's internal code if you actually have registered them both in your webapp's web.xml
(like as many poor quality online tutorials and code sampes do). If a physical Facelets file couldn't be found, it namely fallbacks to JSP as default. If the /faces/*
mapping were matched, then JSF would assume the /index.jsf
to be the physical file. However, it clearly isn't. It's supposed to be the /index.xhtml
.
How exactly did you come to that URL with the double mapping? Was the tutorial you're reading really instructing you like that? Shouldn't you rather instead be using
http://localhost:8080/beginner/index.jsf
or
http://localhost:8080/beginner/faces/index.xhtml
?
Note that the /faces
is in this specific case supposed to be a virtual URL, not an actual folder in the web content of your project sturcture!
In any case ... Those URL mapping patterns are a leftover of legacy JSF 1.x era. Since JSF 2.0, it's possible to just map the FacesServlet
on *.xhtml
directly without messing with virtual URLs.
If you can, get rid of all other <servlet-mapping>
and <url-pattern>
so that you end up with ultimately this for the FacesServlet
:
<servlet>
<servlet-name>facesServlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>facesServlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
Then you can open the page by
http://localhost:8080/beginner/index.xhtml
exactly as its actual path is in the deployment. Straightforward enough.
Upvotes: 6