0

I'm trying to run a simple JSF exemple using JSF 2.2 libraries with Tomcat 8.0.3.0. Libraries and Tomcat are provided out of the box with netbeans 8.

Here is my web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
    <context-param>
        <param-name>javax.faces.PROJECT_STAGE</param-name>
        <param-value>Development</param-value>
    </context-param>
    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>/faces/*</url-pattern>
    </servlet-mapping>
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <welcome-file-list>
        <welcome-file>faces/index.xhtml</welcome-file>
    </welcome-file-list>
</web-app>

The managed bean to display a message

@Named(value = "helloWorldController")
@RequestScoped
public class HelloWorldController {

    private String hello;

    /**
     * Creates a new instance of HelloWorldController
     */
    public HelloWorldController() {
        hello = "Hello World!";
    }

    public String getHello() {
        return hello;
    }

    public void setHello(String hello) {
        this.hello = hello;
    }
}

And index.xhtml

<?xml version='1.0' encoding='UTF-8' ?>
<!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:h="http://xmlns.jcp.org/jsf/html">
    <h:head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <title>Facelet Title</title>
    </h:head>
    <h:body>
        <p>
            #{helloWorldController.hello}
        </p>
    </h:body>
</html>

I tried with different url:

I added Java EE 6 Aeb Api library provided by Netbeans in the path so it is deployed. I also tried with Java EE 7 Web Api Library.

jerome
  • 1,835
  • 3
  • 33
  • 50
  • Do you have a faces-config.xml? Can you post it please? – Ria Apr 11 '15 at 13:09
  • No, I do not have faces-config.xml, do I need one ? – jerome Apr 11 '15 at 13:38
  • I have read that it is not needed since JSF 2.0, as well as the mapping to FacesServlet in web.xml if using servlet 3 container, which Tomcat 8 is. – jerome Apr 11 '15 at 13:53
  • 1
    Are you using CDI in tomcat (such as weld)? If no, did you try use `@ManagedBean` instead of `@Named`? To use `@Named` you need a CDI container. If is it, I post an answer with more details. – Bruno César Apr 11 '15 at 22:46
  • You're right I was not using CDI in Tomcat, but used `@Named`. It works with `@ManagedBean`. Thanks. – jerome Apr 12 '15 at 08:53

0 Answers0