Primefaces Spring Boot Hello World Example – Primefaces Tutorial
Hello and welcome again to elgarnaoui.com, in this tutorials we will create a Hello world using spring boot and JSF primefaces framework.
So let’s start :
Tools used in this tutorial :
- Eclipse 2020-03 or IntelliJ IDEA Community Edition 2020.2
- Spring boot 2.3.2.RELEASE
- Java 8
- Primefaces 5.1
- Myfaces-impl 2.2.6
Let’s create our project :
In eclipse click new > other > Spring Starter Project and click next then choose the name of your project, group, artifact and version :

Next shoose the spring boot version and other dependencies like devtools :

Click Finish, then the project is created now.
Project Structure :
This is the web project structure build using Maven.

Maven dependencies :
In pom.xml file of your maven project, add the dependencies below.
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.sample</groupId>
<artifactId>sample</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>sample</name>
<description>Demo project for Spring Boot</description>
<packaging>jar</packaging>
<properties>
<java.version>8</java.version>
</properties>
<!-- Add typical dependencies for a web application -->
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.apache.myfaces.core</groupId>
<artifactId>myfaces-impl</artifactId>
<version>2.2.6</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.myfaces.core</groupId>
<artifactId>myfaces-api</artifactId>
<version>2.2.6</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-core</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>5.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.primefaces.extensions</groupId>
<artifactId>all-themes</artifactId>
<version>1.0.8</version>
</dependency>
<dependency>
<groupId>org.ocpsoft.rewrite</groupId>
<artifactId>rewrite-servlet</artifactId>
<version>2.0.12.Final</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<!-- Package as an executable jar -->
<build>
<outputDirectory>src/main/webapp/WEB-INF/classes</outputDirectory>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Model class :
In package model create a managed bean java class HelloModel.java with these annotations from JSF to make this class a ManagedBean
@ManagedBean(name = "model", eager = true)
@SessionScoped
HelloModel.java as below :
package com.sample.demo.model;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
/**
* Created by elgarnaoui.com.
*/
@ManagedBean(name = "model", eager = true)
@SessionScoped
public class HelloModel {
private String hello = "Hello /";
private String world = "World/";
public String getHello() {
return hello;
}
public void setHello(String hello) {
this.hello = hello;
}
public String getWorld() {
return world;
}
public void setWorld(String world) {
this.world = world;
}
}
View Class :
In view package create a HelloView.java class extends from the ManagedBean java class HelloWorld.java as below :
package com.sample.demo.view;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import com.sample.demo.model.HelloModel;
/**
* Created by elgarnaoui.com.
*/
@ManagedBean(name = "hello", eager = true)
@RequestScoped
public class HelloView extends HelloModel{
public HelloView() {
super();
// TODO Auto-generated constructor stub
}
}
Demo package :
In this package create FacesRewriteConfigurationProvider.java and Initializer.java and update your SampleAppliction.java as below :
SampleAppliction.java
package com.sample.demo;
import java.util.EnumSet;
import javax.faces.webapp.FacesServlet;
import javax.servlet.DispatcherType;
import org.ocpsoft.rewrite.servlet.RewriteFilter;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
/**
* Created by elgarnaoui.com.
*/
@SpringBootApplication
@EnableAutoConfiguration
@ComponentScan({"com.sample.demo"})
public class SampleApplication extends SpringBootServletInitializer{
public static void main(String[] args) {
SpringApplication.run(SampleApplication.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(SampleApplication.class, Initializer.class);
}
@SuppressWarnings("rawtypes")
@Bean
public ServletRegistrationBean servletRegistrationBean() {
FacesServlet servlet = new FacesServlet();
ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(servlet, "*.jsf");
return servletRegistrationBean;
}
@SuppressWarnings("unchecked")
@Bean
public FilterRegistrationBean rewriteFilter() {
FilterRegistrationBean rwFilter = new FilterRegistrationBean(new RewriteFilter());
rwFilter.setDispatcherTypes(EnumSet.of(DispatcherType.FORWARD, DispatcherType.REQUEST,
DispatcherType.ASYNC, DispatcherType.ERROR));
rwFilter.addUrlPatterns("/*");
return rwFilter;
}
}
FacesRewriteConfigurationProvider.java
package com.sample.demo;
import javax.servlet.ServletContext;
import org.ocpsoft.rewrite.annotation.RewriteConfiguration;
import org.ocpsoft.rewrite.config.Configuration;
import org.ocpsoft.rewrite.config.ConfigurationBuilder;
import org.ocpsoft.rewrite.servlet.config.HttpConfigurationProvider;
import org.ocpsoft.rewrite.servlet.config.rule.Join;
/**
* Created by elgarnaoui.com.
*/
@RewriteConfiguration
public class FacesRewriteConfigurationProvider extends HttpConfigurationProvider {
@Override
public int priority()
{
return 10;
}
@Override
public Configuration getConfiguration(final ServletContext context)
{
return ConfigurationBuilder.begin()
.addRule(Join.path("/sample/").to("/index.jsf"))
.addRule(Join.path("/sample/hello/").to("/index.jsf"));
}
}
Initializer.java
package com.sample.demo;
import org.springframework.context.annotation.Configuration;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
/**
* Created by elgarnaoui.com.
*/
@Configuration
public class Initializer implements org.springframework.boot.web.servlet.ServletContextInitializer {
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
System.err.println("------------------------------------");
servletContext.setInitParameter("primefaces.CLIENT_SIDE_VALIDATION", "true");
servletContext.setInitParameter("primefaces.THEME", "bootstrap");
}
}
Webapp folder :
In this folder create 2 files.xhtml with taglibs from JSF, JSF core, Facelets and PrimeFaces:
layout.xhtml as below :
<?xml version="1.0" encoding="UTF-8"?>
<!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://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:p="http://primefaces.org/ui">
<f:view>
<h:head>
<title><ui:insert name="title">Default title</ui:insert></title>
</h:head>
<h:body>
<div class="ui-grid ui-grid-responsive">
<div class="ui-grid-row">
<div class="ui-grid-col-3"></div>
<div class="ui-grid-col-6"></div>
<div class="ui-grid-col-3"></div>
</div>
<div class="ui-grid-row">
<div class="ui-grid-col-3"></div>
<div class="ui-grid-col-6">
<p:growl for="errors" showDetail="true" autoUpdate="true"/>
<ui:insert name="content">Default content</ui:insert>
</div>
<div class="ui-grid-col-3"></div>
</div>
</div>
</h:body>
</f:view>
</html>
index.xhtml as below :
<?xml version="1.0" encoding="UTF-8"?>
<!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://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:p="http://primefaces.org/ui" >
<ui:composition template="layout.xhtml">
<ui:define name="content">
<p:panelGrid columns="2">
<h:outputText value="#{hello.hello}"/>
<h:outputText value="#{hello.world}"/>
</p:panelGrid>
</ui:define>
</ui:composition>
</html>
Run Application :
Now go to SampleApplication.java > right click >Run As > Java Application and when the tomcat running go to your browser and type http://localhost:8080/sample/hello/ or http://localhost:8080/sample/ as your config in FacesRewriteConfigurationProvider.java and you will get a hello world as :

Thank you for reading this post, to support us share it on social media, and if you have any issues, request or question let me know in the comment section 🙂
Code source :

These are actually impressive ideas in regarding blogging.
You have touched some good factors here. Any way keep up wrinting.
This is a topic that’s near to my heart… Cheers! Exactly where are your contact
details though?
Hi, of course this article is genuinely pleasant and I have learned lot of things from
it concerning blogging. thanks.
you’re in reality a excellent webmaster. The web site loading velocity is incredible.
It kind of feels that you’re doing any distinctive trick.
Also, The contents are masterwork. you have performed a fantastic process on this matter!
I do not even know the way I finished up here,
but I believed this submit was once good. I do not recognise who you’re but certainly you
are going to a well-known blogger when you aren’t already.
Cheers!
Every weekend i used to go to see this web page, for the reason that
i want enjoyment, as this this site conations really pleasant funny stuff too.
Awesome blog! Is your theme custom made or did you download it
from somewhere? A theme like yours with a few simple tweeks would really make my blog jump out.
Please let me know where you got your theme. Bless you
Informative article, just what I needed.
Thanks designed for sharing such a fastidious thinking, post is pleasant, thats why
i have read it fully
When I originally commented I clicked the “Notify me when new comments are added” checkbox and now each time a comment is added I get four
e-mails with the same comment. Is there any way you can remove people from that service?
Many thanks!
I like it whenever people get together and share opinions.
Great website, continue the good work!
I got this website from my friend who informed me regarding this web site and at the moment this time I am browsing
this web page and reading very informative content
at this time.
Thank you for the auspicious writeup. It in fact was
a amusement account it. Look advanced to more added
agreeable from you! By the way, how can we communicate?
I all the time emailed this webpage post page to all my contacts, for the reason that if like to read it after that my friends
will too.
naturally like your web-site but you need to check the spelling on quite a few of your posts.
Several of them are rife with spelling problems
and I find it very bothersome to tell the truth however I’ll definitely come back again.
I have been surfing on-line greater than 3 hours nowadays,
but I never discovered any fascinating article like yours.
It’s beautiful worth sufficient for me. Personally, if all site owners and bloggers made just right content material
as you probably did, the net might be a lot more useful than ever before.
Every weekend i used to pay a visit this website, because i wish for enjoyment, as this this web
page conations in fact nice funny stuff too.
We are a group of volunteers and starting a new scheme in our community.
Your web site offered us with valuable info to work on. You have done an impressive job and our
whole community will be thankful to you.
Pretty element of content. I simply stumbled upon your blog and in accession capital to
say that I acquire in fact enjoyed account your blog posts.
Anyway I’ll be subscribing to your augment or even I fulfillment you get right
of entry to constantly rapidly.
What’s up i am kavin, its my first time to commenting anywhere, when i read this post i thought i could also create comment due
to this good piece of writing.
When someone writes an post he/she maintains the idea of a user in his/her brain that how a
user can be aware of it. Thus that’s why this article is perfect.
Thanks!
This design is steller! You obviously know how to keep a reader amused.
Between your wit and your videos, I was almost moved to start
my own blog (well, almost…HaHa!) Wonderful job. I really loved what you had to say,
and more than that, how you presented it. Too cool!
Have you ever thought about adding a little bit more than just your articles?
I mean, what you say is valuable and all. However think of if you added some great photos or videos to give your posts more, “pop”!
Your content is excellent but with pics and clips, this blog could definitely be
one of the best in its field. Very good blog!
Inspiring story there. What occurred after? Good luck!
Fine way of explaining, and pleasant piece of writing to take information on the topic of my presentation topic, which i am going to present in institution of higher education.
I was curious if you ever thought of changing the page layout of your website?
Its very well written; I love what youve got to say.
But maybe you could a little more in the way of content so people could connect with it better.
Youve got an awful lot of text for only having 1 or 2 images.
Maybe you could space it out better?
Hmm is anyone else having problems with the images on this blog loading?
I’m trying to determine if its a problem on my end or if it’s the
blog. Any suggestions would be greatly appreciated.
My spouse and I stumbled over here coming from a different website and thought I might check things out.
I like what I see so i am just following you. Look forward to looking at your
web page repeatedly.
It’s amazing in favor of me to have a web page, which is beneficial designed for my knowledge.
thanks admin
Spot on with this write-up, I really think this site needs much more attention. I’ll probably
be returning to see more, thanks for the information!
Does your site have a contact page? I’m having trouble locating it but, I’d
like to shoot you an e-mail. I’ve got some ideas for your blog you might be interested
in hearing. Either way, great website and I look
forward to seeing it develop over time.
I’m gone to inform my little brother, that
he should also visit this web site on regular basis to take updated from most
recent reports.
I used to be able to find good advice from your articles.
Great article.
We are a group of volunteers and starting a new scheme in our community.
Your web site offered us with valuable information to work on. You’ve done a formidable job and our whole community will be thankful
to you.
This is a topic which is close to my heart…
Thank you! Where are your contact details though?
What’s up, its pleasant piece of writing about media print, we all know media is
a great source of facts.
Neat blog! Is your theme custom made or did you download it from somewhere?
A design like yours with a few simple adjustements would really make my blog shine.
Please let me know where you got your theme. Many thanks
Do you have any video of that? I’d care to find out more details.
Simply desire to say your article is as surprising.
The clarity in your post is simply excellent and i could assume you are an expert on this subject.
Well with your permission allow me to grab your
RSS feed to keep up to date with forthcoming post. Thanks a million and
please carry on the rewarding work.
What you composed was actually very logical.
However, what about this? suppose you were to write a awesome headline?
I ain’t saying your information isn’t good, but what if you added a post title to possibly grab a
person’s attention? I mean Primefaces Spring
Boot Hello World Example – Primefaces Tutorial is kinda vanilla.
You ought to glance at Yahoo’s front page and watch how they create post headlines to grab
viewers interested. You might try adding a video or a related picture or two to get readers excited about what you’ve written. In my opinion,
it could bring your posts a little bit more interesting.
I was able to find good advice from your blog articles.
Hey! I know this is kind of off-topic however I needed to ask.
Does managing a well-established website like yours take a massive
amount work? I’m completely new to operating a blog but I do
write in my journal daily. I’d like to start a blog so I can share my personal experience and thoughts online.
Please let me know if you have any kind of recommendations or tips
for new aspiring bloggers. Appreciate it!
There’s definately a lot to learn about this topic.
I like all of the points you’ve made.
Very good information. Lucky me I found your website
by chance (stumbleupon). I have saved it for later!
Definitely believe that which you said. Your favorite justification appeared to be on the web
the easiest thing to be aware of. I say to you, I definitely get annoyed while people think about
worries that they plainly do not know about. You managed to hit the nail upon the top and also defined out
the whole thing without having side-effects , people
can take a signal. Will probably be back to get more.
Thanks
Good day! I know this is somewhat off topic but I was wondering which blog platform
are you using for this site? I’m getting sick and tired of WordPress
because I’ve had issues with hackers and I’m looking at alternatives for another platform.
I would be fantastic if you could point me in the direction of a good platform.
Awesome article.
When someone writes an piece of writing he/she maintains
the thought of a user in his/her mind that how a user can know it.
So that’s why this piece of writing is perfect.
Thanks!
Howdy this is somewhat of off topic but I was wondering if blogs use WYSIWYG editors or if you
have to manually code with HTML. I’m starting
a blog soon but have no coding skills so I wanted to get advice from someone with experience.
Any help would be greatly appreciated!
Hello there I am so grateful I found your blog, I really found you by mistake, while I was browsing on Digg for something else,
Regardless I am here now and would just like to say many thanks for
a remarkable post and a all round enjoyable blog (I also love the theme/design), I don’t have time to go through it all at the moment but I have book-marked
it and also added in your RSS feeds, so when I have time I will
be back to read much more, Please do keep up the superb work.
I could not resist commenting. Very well written!
certainly like your web-site however you need to
take a look at the spelling on quite a few of your posts.
Many of them are rife with spelling issues and I find
it very bothersome to inform the truth on the other
hand I will definitely come back again.
This piece of writing gives clear idea designed for the new viewers of blogging,
that genuinely how to do blogging.
Do you have a spam problem on this website; I also am a blogger, and I was wanting to
know your situation; we have created some nice procedures and we are looking to
exchange methods with others, be sure to shoot me an e-mail if interested.
Hello there! This is my first comment here so I
just wanted to give a quick shout out and say I really enjoy reading through your articles.
Can you suggest any other blogs/websites/forums that cover the same subjects?
Thank you!
Very descriptive post, I loved that a lot. Will
there be a part 2?