logo

JSF & PrimeFaces & Spring tutorial 1: Hello World JSF

Let's create Hello World JSF

download result: https://app.box.com/s/1s44rq3hy74onw3wcop2

pom.xml:
<dependency>
	<groupId>org.primefaces</groupId>
	<artifactId>primefaces</artifactId>
	<version>5.1</version>
</dependency>
<dependency>
	<groupId>org.glassfish</groupId>
	<artifactId>javax.faces</artifactId>
	<version>2.2.9</version>
</dependency>
<dependency>
	<groupId>javax.servlet</groupId>
	<artifactId>javax.servlet-api</artifactId>
	<version>3.1.0</version>
	<scope>provided</scope>
</dependency>
web.xml:
<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>
<servlet-mapping>
	<servlet-name>Faces Servlet</servlet-name>
	<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<listener>
	<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>
<context-param>
	<param-name>javax.faces.FACELETS_REFRESH_PERIOD</param-name>
	<param-value>0</param-value>
</context-param>
<context-param>
	<param-name>javax.faces.PROJECT_STAGE</param-name>
	<param-value>Development</param-value>
</context-param>
<context-param>
	<param-name>javax.faces.FACELETS_SKIP_COMMENTS</param-name>
	<param-value>true</param-value>
</context-param>
HelloController.java:
import javax.faces.bean.ManagedBean;

@ManagedBean
public class HelloController {

	public String showHello() {
		return "hello from managed bean";
	}
}
index.xhtml:
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://xmlns.jcp.org/jsf/html"
	xmlns:p="http://primefaces.org/ui">
  <h:head>
  </h:head>
  <h:body>
    managed bean says:
    #{helloController.showHello()}
  </h:body>
</html>

comments powered by Disqus

rss

Free online Java web application examples

Want to develop whole web applications which use database, security and more? See my github account, where are lot's of example projects:
github

Search