0

I'm creating a Web Application with Maven in Eclipse. When I deploy its war-file to my local tomcat the JSF content doesn't show up in the browser. This is my home.xhtml file:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:f="http://java.sun.com/jsf/core"      
      xmlns:h="http://java.sun.com/jsf/html">
    <h:head>
        <title>JSF Test</title>
    </h:head>
    <h:body>
        <h3>Test</h3>
        #{helloWorld.message}
    </h:body>
</html>

Only the header shows up in the browser. The page source shows this:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head>
        <title>JSF Test</title></head><body>
        <h3>Test</h3>


    </body>
</html>

I'm accessing localhost:8080/test/home.xhtml, the mapping for .xhtml is enabled:

<servlet-mapping>
    <servlet-name>facesServlet</servlet-name>
    <url-pattern>*.xhtml</url-pattern>
</servlet-mapping>

This is the HelloWorld class:

package com.tutorialspoint.test;

import javax.faces.bean.ManagedBean;

@ManagedBean(name = "helloWorld", eager = true)
public class HelloWorld { 
    public HelloWorld() { 
        System.out.println("HelloWorld started!"); 
    } 
    public String getMessage() { 
        return "Hello World!"; 
    } 
}

The page is obviously being processed, otherwise the #{helloWorld.message} command would show up in the page source code and the browser would render it as plain text. So what could be the problem? Thanks!

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
user3249829
  • 127
  • 1
  • 1
  • 6
  • 1
    Check my comment on your previous question: http://stackoverflow.com/questions/25405894/java-lang-noclassdeffounderror-javax-faces-context-facescontextfactory#comment39629619_25406594 Apparently there's **indeed** more at matter! Apparently you still have a bogus JSF API library somewhere in runtime classpath. As answered on your previous question, exploring the `/WEB-INF/lib` folder of the Maven-built WAR file must give clues. – BalusC Aug 21 '14 at 09:32
  • @BalusC Both jsf-api and jsf-impl are version 2.1.7, I have no `faces-config.xml`. – user3249829 Aug 21 '14 at 09:34
  • @BalusC The `/WEB-INF/lib` folder only contains `javax.servlet-api-3.0.1.jar`, `jsf-api-2.1.7.jar` and `jsf-impl-2.1.7.jar`. – user3249829 Aug 21 '14 at 09:47
  • The servlet API absolutely doesn't belong there. This is supposed to be already provided by the servlet container itself and absolutely not by the webapp. Get rid of it and retry. – BalusC Aug 21 '14 at 09:48
  • @BalusC When I delete it, the `#{helloWorld.message}` shows up as plain text. – user3249829 Aug 21 '14 at 10:34
  • 1
    Wow your runtime classpath must be an absolute mess. You seems to have a yet older Servlet API version wandering in there. First of all, which Tomcat version exactly are you using? If it's 7 or newer, then it should work just fine. If you had no clue what you did as to the runtime classpath, I strongly suggest to trash everything and restart over as to installing JDK, JRE, Tomcat, etc. – BalusC Aug 21 '14 at 10:35
  • @BalusC I'm using XAMPP with a tomcat 7. Can you recommend a tutorial on how to set up everything so I don't screw it up again? – user3249829 Aug 21 '14 at 10:58
  • I'll repost it as an answer. As to learning JSF, start here: http://stackoverflow.com/tags/jsf/info I've a 3 year old JSF 2.0 tutorial at my blog, but it's using GlassFish which I don't recommend anymore these days. I'm currently by the way working on a new JSF 2.2 tutorial with WildFly. – BalusC Aug 21 '14 at 12:34

1 Answers1

3

JSF being unable to discover the managed beans suggests that there's a different versioned JSF API somewhere else in the runtime classpath outside the webapp's library. EL being unable to be parsed and executed suggests that there's a different versioned Servlet or EL API somewhere else in the runtime classpath outside the servletcontainer's library. The webapp's runtime classpath covers among others webapp's own /WEB-INF/lib folder, Tomcat's own /lib folder and JRE's own /lib and /lib/ext folders.

If you make sure that you never touch Tomcat's and JRE's library folders (provided that you're using fresh Tomcat install from http://tomcat.apache.org and fresh JRE install from http://java.com), and make sure that webapp's /WEB-INF/lib doesn't contain libraries which are already provided by Tomcat or JRE itself (such as Servlet API), then world should be well.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • I just noticed that it works when I don't use Maven (I created a new project and added the JSF library manually), but when I try to set it up as a Maven project with JSF added as a dependency it is simply not rendering the HelloWorld message. Doesn't that imply that it's not a problem with the classpath? – user3249829 Aug 21 '14 at 12:53
  • Maven takes over among others the building of the WAR file and filling the `/WEB-INF/lib`. This problem thus suggests that it did it wrong, likely by misconfiguration. – BalusC Aug 21 '14 at 12:54