Reputation: 3046
I'm trying to get started with JSF 2.2 in Eclipse with glassfish.
Here's what I did:
new maven project with no archetype selected (skipped archetype selection), I configure the maven project with war as packaging
I change the compiler level to 1.7
In the project facets, I choose JavaServerFaces 2.2 Project, select glassfish as runtime, change Java to 1.7 and Dynamic Web Module to 3.1
I add the following dependency:
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.faces</artifactId>
<version>2.2.8</version>
</dependency>
I create an index.xhtml file in the webapp folder:
<!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"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
>
<h:head/>
<h:body>
TEST
</h:body>
</html>
I run the index.xhtml on the glassfish server and go to http://localhost:8080/JavaServerFaces/index.xhtml
and see TEST.
I create a JavaBean in the src/main/java
folder:
import javax.inject.Named;
@Named
public class TestBean {
private String name;
public TestBean() {
name = "TESTNAME";
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
I access that bean in my index.xhtml
<h:body>
TEST
Welcome #{testbean.name}
</h:body>
I run it on the server and get the following output:
TEST Welcome #{testbean.name}
I don't get any errors.
What did I miss or configure incorrectly? I didn't change anything in the web.xml
or faces-config.xml
because I read that they're optional.
Thanx a lot for help and tips!
Upvotes: 0
Views: 989
Reputation: 8624
In your web.xml
you have to configure javax.faces.webapp.FacesServlet
as follows
<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>*.xhtml</url-pattern>
</servlet-mapping>
The access http://localhost:8080/JavaServerFaces/index.xhtml
it should work.
Upvotes: 1