0

I'm new to Java EE and I'm currently trying to code a simple hello world program using JavaServer Faces. However, I'm having some problems with the expression language in the JSF not evaluating after running the application. I've looked online and the answers regarding expression language not evaluating weren't able to solve my problem. In my project facet I have set JSF to version 2.0, also I've noticed that I am using servlet 3.0 as per the web.xml. I've provided my code below.

Hello.java

package jsf.hello;

import javax.faces.bean.ManagedBean;

@ManagedBean
public class Hello {

    final String world = "Hello World!";

    public String getWorld(){

        return world;

    }

}

hello.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://java.sun.com/jsf/html">
<h:head>
    <title>Hello World</title>
</h:head>
<h:body>
    #{hello.world}
</h:body>
</html>

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee"     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee     http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>JSFHelloWorld</display-name>
  <welcome-file-list>
    <welcome-file>hello.xhtml</welcome-file>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
  <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>
</web-app>
KV6
  • 1
  • What does that mean, "not evaluating"? You see nothing, or you literally see `#{hello.world}' in the browser? – Gimby Oct 18 '17 at 15:50
  • Thanks Balus. I tried changing the url pattern to use *.xhtml, however that did not work. – KV6 Oct 19 '17 at 21:47
  • Hi Gimby. I actually see #{hello.world} in the browser. – KV6 Oct 19 '17 at 21:48

0 Answers0