PrimeFaces hello world example

In this tutorial, we will show you how to create a JSF 2 + PrimeFaces wed project, the final output is display a “hello world” string in PrimeFaces editor component.

Tools used :

  1. JSF 2.1.11
  2. Primefaces 3.3
  3. Eclipse 4.2
  4. Maven 3
  5. Tested on Tomcat 7
PrimeFaces only requires a JAVA 5+ runtime and a JSF 2.x implementation as mandatory dependencies.

1. Project Directory

Final project directory.

project directory

2. Project Dependency

To use PrimeFaces, you only need single primefaces-{version}.jar, but this jar is not available on Maven central repository, So, you need to declare PrimeFaces own repository :

Refer here : PrimeFaces download reference

		<name>Prime Repo</name>

File : pom.xml – Add JSF 2 and Primefaces dependencies.

<project xmlns="" 
	<name>primefaces Maven Webapp</name>
			<name>Prime Repo</name>
		<!-- PrimeFaces -->
		<!-- JSF 2 -->
		<!-- EL -->
		<!-- Tomcat 6 need this 

3. Editor Bean

Create a simple bean, to provide data for PrimeFaces editor component later.

File :

package com.mkyong.editor;
import javax.faces.bean.ManagedBean;
@ManagedBean(name = "editor")
public class EditorBean {
	private String value = "This editor is provided by PrimeFaces";
	public String getValue() {
		return value;
	public void setValue(String value) {
		this.value = value;

4. Web Page

To use PrimeFaces components, just declares this namespace xmlns:p="", and start use it, simple.

File : index.xhtml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
<html xmlns=""
	<h1>Hello World PrimeFaces</h1>
	   <p:editor value="#{editor.value}" />

5. Configuration

PrimeFaces does not require any mandatory configuration

See web.xml below, only for JSF configuration.

File : web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi=""
	id="WebApp_ID" version="2.5">
  <display-name>PrimeFaces Web Application</display-name>
  	<!-- Change to "Production" when you are ready to deploy -->
	<!-- Welcome page -->
	<!-- JSF mapping -->
		<servlet-name>Faces Servlet</servlet-name>
	<!-- Map these files with JSF -->
		<servlet-name>Faces Servlet</servlet-name>
		<servlet-name>Faces Servlet</servlet-name>
		<servlet-name>Faces Servlet</servlet-name>
		<servlet-name>Faces Servlet</servlet-name>

6. Demo

See final output. http://localhost:8080/primefaces/

hello world result

Download Source Code

Download it – (8 kb)


  1. PrimeFaces Official Website
  2. JSF 2 hello world example
Tags :

About the Author

Founder of and, love Java and open source stuff. Follow him on Twitter, or befriend him on Facebook or Google Plus. If you like my tutorials, consider make a donation to these charities.


  • GYana

    Sir Your above code works fine with tomcat .. But I am using IBM WASCE and Eclipse on which it is not publishing can u suggest some solutions ?

  • Carmen

    Grazie di esistere !

  • John Betts

    Hi Mr. Yong

    I am getting this warning when I run this project:

    Warning: This page calls for XML namespace declared with prefix p but no taglibrary exists for that namespace.

    What can I do?


    • John Betts

      I created a new project with the same files and all is right. Thanks

    • Monish Sen

      Add prime faces jar to Tomcat (or any other web server’s) lib folder

  • John Betts

    Hi Mr. Yong I am getting the following message:

    Warning: This page calls for XML namespace declared with prefix p but no taglibrary exists for that namespace.

    What can I do?

    • John Betts

      I created a new project with the same files and all is right. Thanks

  • josh

    Hi mkyong,
    I’m quite new to the Primefaces and urgently need some help from professionals such as you. Thank you in advance for your time.

    I have a simple JSF2.0 Dynamic Web Project (not Maven) using Myfaces JSF Core API library and running on Tomcat7 with Eclipse Juno.

    Due to the need of connecting to Database, I added the JPA2.0 to project facelet using Eclipselink as provider. So the structure is somehow like JPA->backing bean files->xhtml files.
    Everything seems fine so far, I can get data in the .java tester class. However when I try to run the xhtml pages, it always cause tomcat ‘Java heap’ problem and cannot start (popup error dialog: Server Tomcat v7.0 Server at localhost was unable to start within 45 seconds. If the server requires more time, try increasing the timeout in the server editor.)

    After some testing, I found the error is because I have eclipselink.jar file in the WEB-INF/lib. If I remove this jar file, the page renders without problem. However, without this library file, some pages which need the backing bean parameters got error (javax.persistence.PersistenceException – No Persistence provider for EntityManager named xxx)

    So I have no solution for my current situation. One hand I need the eclipselink.jar file to make my pages able to ‘read/write’ from the backing bean, on the other hand I cannot include this specific library because it seems ‘clash’ withe PrimeFaces library/configuration.

    Would you kindly provide me some advice or any other alternative solutions?

    Thanks again for your help.
    Regards, Josh.

  • Jay Jay

    Hello mkyong

    Thanks for all the nice articles.

    Once I add the primeface repository like this…..

    PrimeFaces Maven Repository

    Maven build give me logs like below… in which all my local projects are getting downloaded from the primefaces repository instead of my local machine.
    How can I fix this ?

    Thanks in advance.


  • Frank Analysis

    Thanks Mykyong, you not only taught me how to set up a PrimeFaces project, but also taught me a bit about Maven. I really enjoy your tutorials, you get to the main points and don’t waste time on irrelevant stuff. Cheers

  • Junior

    Very Good. Thanks

  • Ezequiel Barbosa

    Hello mkyong,

    First come talk that his work was excellent. But I would like to know what I need to change this pom to the war, also run the JBoss EAP 5.1.

    Thank you

  • Peter Drinnan

    Thanks so much Mkyong. I’ve been banging my head with this for a while and found your article and example made it very clear finally.

  • Hiten

    Thanks for sharing this example. However, I had small issue with jsf-api.jar when I tried with ‘mvn compile’. I checked the maven repository ‘’ to navigate the exact group id, artifact id, version to be used for jsf-api.jar. Thereby modified the pom.xml to the below and it worked great.


  • Sammok

    Great. Worked. Just added the jars to lib folder for running it in eclipse local tomcat instance.

  • yonglei

    Hi, Yong
    I deploy your demo helloworld project into tomcat7.0.29 and got following error. I verified that the file jsf-impl-2.1.11.jar does not contain class javax.faces.webapp.FacesServlet, what’s the problem, thanks.

    java.lang.ClassNotFoundException: javax.faces.webapp.FacesServlet
    at org.apache.catalina.loader.WebappClassLoader.loadClass(
    at org.apache.catalina.loader.WebappClassLoader.loadClass(
    at org.apache.catalina.core.DefaultInstanceManager.loadClass(
    at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(
    at org.apache.catalina.core.DefaultInstanceManager.newInstance(
    at org.apache.catalina.core.StandardWrapper.loadServlet(
    at org.apache.catalina.core.StandardWrapper.load(
    at org.apache.catalina.core.StandardContext.loadOnStartup(
    at org.apache.catalina.core.StandardContext.startInternal(
    at org.apache.catalina.util.LifecycleBase.start(
    at org.apache.catalina.core.ContainerBase$
    at org.apache.catalina.core.ContainerBase$
    at java.util.concurrent.FutureTask$Sync.innerRun(
    at java.util.concurrent.ThreadPoolExecutor.runWorker(
    at java.util.concurrent.ThreadPoolExecutor$

    • yonglei

      change jsf-impl and jsf-api ‘s version to 2.0.1 resolved this issue. but I have no idea why you are ok with the version 2.1.11 of jsf-impl in you pom.xml

  • DuyMao

    I’m a new comer to JSF and PrimeFaces. I have a table with many row; and a command button was disabled, requirement is when clicking on data row, the button is enabled, and when clicking outside of table, the button is disabled.

    I don’t know can PrimeFaces or JSF do this ? Or i have to do with JQUERY?
    Please help me. Thank in advance!

    • leon

      go to primefaces website’s Demo part.
      A lot of existing code there for you.

  • Neha Khaana

    Hi Mkyong,

    I am facing same problem as Amandeep. Can you suggest how to deploy it as a WAS app?

  • Rafael

    Hi Mkyong
    i have a problem.


    Warning: This page calls for XML namespace declared with prefix p but no taglibrary exists for that namespace

    why?, my proyect show this error and o don´t have idea…
    please help´me!!

  • Amandeep

    Hi mkyong.

    This is a great sample project. I am having tough time deploying this to WAS 8 server. Can you tell me if i require additional dependencies in the pom to make this work?

    Appreciate the help

    • Ken Masters

      Actually, you don?t have to add, but to quit the JSF 2 jars. I have the problem that I cannot deploy this example in WAS, and I find out that it was because WAS already have a JSF implementation, so the jars that are contained in the project were making a conflict with the ones that WAS already have. Just quit them from the pom and deploy.

      Hope it can help you

  • mehdi

    i have tried your example but when i download the primefaces jar file, i dont know where i have to paste it.

    • Max Rohoden

      Paste it on C:\Program Files\NetBeans 7.1.2\java\modules\ext then go to your project properties and add the main .jar file to the compile tab.

  • Vamshi

    Hey Mykong.. I have one issue with the primefaces if you can help.. we are getting view expired exception when we navigate back using browser button using the primefaces and jsf2. can you guide me how to fix it

  • Alvin Sim

    I would like to ask regarding the maven pom file. I am currently trying out primefaces and I use maven to create the project. In the pom file, I only have primefaces defined in the dependency and then deploy to Glassfish. By looking at your pom file, is it necessary to define the JSF2 and EL dependencies?

    The dependencies I defined are as below:

    • mkyong

      Above example is deployed on Tomcat 6 or 7, so the JSF and EL dependencies are required.

      For Glassfish, it already bundled with required JSF and EL jars, so the declare at pom file is no longer required.

      • Alvin Sim

        Ooh.. ok.. now I understand.. Thanks :)

  • Gezzer