I started to learn JSF. I use netbeans and glass fish as server. I have this problem:
my code of start.xhtml
:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<h:head>
<h:outputStylesheet library="css" name="default.css"/>
<title>some text</title>
</h:head>
<h:body>
<h:graphicImage library="images" name="wave.med.gif"
alt="duke waving"/>
<h2>
hi #{user.minimum} a #{user.maximum} .
</h2>
</h:body>
code of User.java
:
@Named(value = "user")
@SessionScoped
public class User implements Serializable {
private long minimum=0;
private long maximum=10;
public User() {
}
public long getMinimum(){ return (this.minimum);}
public long getMaximum(){ return (this.maximum);}
public void setMaximum(long m){ this.maximum=m;}
public void setMinimum(long m){ this.minimum=m;}
}
code of web.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.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>start.xhtml</welcome-file>
</welcome-file-list>
</web-app>
when I deploy the app I get this message only:
hi #{user.minimum} a #{user.maximum}
.
Instead of a picture: wave.med.gif
and message:
hi 0 a 10
.
where could be the problem ?
I guess the problem is that your JSF code isn't evaluated.
You can prove this by looking at the source code of the generated HTML, if it is the same as the code in your start.xhtml, the code isn't evaluated.
To fix this, change the servlet-mapping in your web.xml
to the following:
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
and access the page via http://localhost:8080/YOUR_WEBAPP/start.xhtml