Tomcat 7: Setting up JSF 2

Ensure you have the JSF reference implementation. Using gradle this would be:

	compile 'com.sun.faces:jsf-api:2.1.19'
	compile 'com.sun.faces:jsf-impl:2.1.19'

In your web.xml file you must have:

	<?xml version="1.0" encoding="UTF-8"?>
	<web-app version="3.0"
		  <servlet-name>Faces Servlet</servlet-name>
		  <servlet-name>Faces Servlet</servlet-name>

This includes the faces servlet, and sets up a serlvet mapping that intercepts anything that has the faces/* url. Our welcome file will be hello.xhtml.

In our WEB-INF/ folder we now need to define that hello.xhtml file:

	<?xml version='1.0' encoding='UTF-8' ?>
	<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
	<html lang="en"
		<title>Facelets Hello World</title>

Now the differing h namespace that includes all the JSF tags. We'll look at those later.

Now if you go to http://localhost:8080/YOUR_WAR_NAME/faces/index.xhtml you'll see your face. http://localhost:8080/YOUR_WAR_NAME/ will go to the same thanks to the welcome-file-list above.

java-tomcat java-jsf java

Edit on github
comments powered by Disqus
Click me