PrimeFaces Theme Development - Sample Chapter
PrimeFaces Theme Development - Sample Chapter
$ 34.99 US
22.99 UK
P U B L I S H I N G
pl
C o m m u n i t y
Sudheer Jonna
Sa
m
Andy Bailey
ee
PrimeFaces Theme
Development
Fr
E x p e r i e n c e
D i s t i l l e d
PrimeFaces Theme
Development
Create, package, and customize stunning themes using
PrimeFaces
Andy Bailey
Sudheer Jonna
This is his first publication. However, he has helped review other publications,
including PrimeFaces Cookbook.
Sudheer Jonna was born in Andhra Pradesh, India, in 1987. Currently, he works
as a senior software engineer in Chennai, India. He completed his master's degree
in computer applications from JNTU. In the past 4-5 years, he worked on providing
architectural designs and building various web applications based on JSF, Struts,
Spring, jQuery, JPA, EJB, and various Java EE and frontend technologies.
He is a JSF and PrimeFaces expert. He has been working with the PrimeFaces
component library since 2011. He worked as a committer and project member
of PrimeFaces and PrimeFaces Extensions open source projects. He has been a
well-known, recognized member of the PrimeFaces community for the past few
years. He is also the author of Learning PrimeFaces Extensions Development and
PrimeFaces BluePrints books, Packt Publishing. He worked as reviewer for PrimeFaces
Beginner's Guide and community reviewer for many other books.
Besides working with the aforementioned technologies, he also writes technical
articles, provides online training, designs and develops web application architecture,
writes books and reviews, and provides suggestions through online forums and
blogs. He is interested in the research and development of various popular Java
EE frameworks and many other latest technologies.
He shares his knowledge through GitHub (https://github.com/sudheerj).
He recently started blogging (http://sudheerjonna.blogspot.in/).
You can follow him on Twitter (@SudheerJonna) or contact him on Gmail at
[email protected].
Preface
One of the most popular and commonly used web application frameworks
today is JavaServer Faces (JSF) 2.2. Since the introduction of JSF 2, there are a
plethora of component libraries that provide more functionality than that provided
by standard JSF components. PrimeFaces is one of the leading component libraries
available today.
PrimeFaces not only provides a rich set of UI components, but also has the concept
of themes integrated from the beginning. PrimeFaces themes use jQuery UI as a
foundation, which makes adapting to the existing or creating completely customized
themes a gentle and rewarding process. Because jQuery UI is used to create themes,
there is a plethora of documentation and tools available for you to use. This makes
working with PrimeFaces themes very easy.
This book is aimed at the developers of Java Server Faces web applications; these
applications use the PrimeFaces component library. Together, we are going to have a
look at how to use built-in PrimeFaces themes, adjust these themes to fit a particular
application's needs, and finally create custom themes for both desktop- and mobilebased web apps. By the time you have read this book and worked on the examples
provided in its chapters, you will hopefully have gained valuable insights into the
PrimeFaces technology, and especially into how PrimeFaces themes can be used to
enrich user experience for your applications.
The practical exercises in the book can be run using any web server that supports
JSF2/2.2 and Java 6+. The IDE used for the examples in the book was NetBeans 8.0.1,
but any IDE that supports Maven and a suitable web/application server can be used
in its place.
Preface
Preface
Chapter 10, Theme Design Best Practices, looks at best practices in theme development.
We will also look at generally applicable best practices in web design as well as those
for rich Internet applications and PrimeFaces themes.
Chapter 11, Premium Themes and Layouts, and Third-party Converter Tools, explores the
usage of premium themes and layouts and how modern technologies such as LESS
CSS Preprocessor, the Google Material Design language, and so on, introduced in
them to provide amazing templates. This chapter also introduces third-party theme
converter tools that are available in the market.
To Skin an App
In this chapter, you will be introduced to the PrimeFaces JSF (short for JavaServer
Faces) component library, and you will create a Maven-based JSF web application.
This application will be used throughout the book to demonstrate and test the things
that we will learn in each chapter and section.
In this chapter, we will cover the following topics:
[1]
To Skin an App
[2]
Chapter 1
[3]
To Skin an App
Now that we have set the name and location of the project, click on Next. This leads
us to the Settings dialog box. This is where we set the application server and Java
Enterprise Edition (EE) version that we are going to use for the project, as shown
in the following screenshot:
Chapter 1
Once we have set the project settings, we can finish creating it. NetBeans presents us
with a Project view containing our newly created project. If it hasn't opened a Project
view, open the Windows menu and select Projects. You can also open a Files and a
Services view. This allows us to check the files as they are built into the project, and
through the Services view we can control things such as the GlassFish server, as well
as other services such as database connections.
Now that we have successfully created the project, we have to change the project
properties so that it adds the JSF framework to it.
The JSF framework is part of the Java EE 7 standard version. It
allows developers to build views/pages that are separate from the
business logic and data models that make up the middle tier of
data-driven applications. Because PrimeFaces builds on the facilities
provided by JSF, we need to add it to our project.
Select the project and right-click on it. This opens a context menu, which
allows us to perform different tasks and control various aspects of the project itself.
We are interested in the one at the bottom, Properties. We click on it to open the
Project Properties dialog box and select the Frameworks option, as shown in the
following screenshot:
[5]
To Skin an App
By clicking on the Add button to the right, we can select a framework from a
number of choices. We want JSF, so we select it and click on OK, as follows:
We return to the Project Properties | Frameworks dialog box, which looks like this:
[6]
Chapter 1
The three tabs, Libraries, Configuration, and Components, are used to display and/
or change the configuration of the JSF framework for our project. Libraries cannot be
altered, but it shows that we are using Java EE 7 JSF version 2.2. I also changed the
configuration as follows:
The JSF Servlet URL Pattern field has been changed to *.xhtml from the default one
because it makes the linking of JSF pages easier. However, this is a purely personal
preference and it is not something that you need to do.
The Components tab does allow us to add the PrimeFaces library to
our project. However, it adds the version bundled with NetBeans,
and not the one that we will be using for our project, which is
PrimeFaces 5.2 at the time of writing this book.
[7]
To Skin an App
Once you have set up the JSF framework to your satisfaction, click on OK, and the
changes will be applied to our project.
While we have been doing this, NetBeans should have been building
the project in the background, including the creation of the project
from its Maven archetype. Maven downloads quite a large number
of files when a project is created. Luckily for us, it only does this
once. Maven also maintains a local repository of resources on our
workstation for us so that once a file is downloaded from the Maven
Central Repository it doesn't need to be download from there again.
[8]
Chapter 1
Other Sources: This allows us to add other types of files which may
be needed for the project. We will use this facility. So, its purpose
should become clear, eventually.
[9]
To Skin an App
Usually, you only have the Search tab available in a newly created project.
Maven allows us to add local projects as dependencies to a project,
which is what the Open Projects tab is for. It also allows us to add
dependencies that are defined in a parent Maven project file, and
this is what the Dependency Management tab is for.
3. Type org.primefaces into the Query field of the Search tab, and then go
and make a drink or something that takes a little time.
Not only have we earned a break, but we also need time to
allow Maven to download and install the Maven Central
Repository index in our local Maven repository. This takes time
because there are a very large number of resources available
there. If you already use Maven for your projects, you obviously
won't need a lot of time. The break might be welcome, though.
Once the Maven Central Repository index is available, you will see
something like this:
[ 10 ]
Chapter 1
4. Select the 5.2 version and click on Add. Maven then adds the dependency
to our project.
[ 11 ]
To Skin an App
Although PrimeFaces does not require any additional dependencies, GlassFish does
check each JAR file for optional dependencies and treats them as mandatory ones.
Because of this rather petty strictness, we also need to add the commons-fileupload
and commons-io dependencies. These are only required for the PrimeFaces
fileupload component, which won't be used here. At the time of writing this book,
GlassFish does not allow applications to be run with unsatisfied dependencies. So, we
need to add the missing dependencies.
Add a dependency as you did before, but this time type in commons-fileupload in
the query field and select version 1.3.1. Don't forget to click on Add before adding
the commons-io dependency. For this, you select the 2.1 version.
Now that we have got the project running, we can add the other configuration files
that we saw in an earlier screenshot.
[ 12 ]
Chapter 1
Summary
Well done. You made it to the end of the first chapter with a working project and
learned the repeatable steps that are required to create any PrimeFaces JSF web
project using Maven.
In this chapter, we have successfully created a NetBeans Maven web project using
the new project wizard, added the JSF framework to the project by adjusting the
Project Properties, added the PrimeFaces component library as a dependency using
Maven, added additional libraries as dependencies using Maven, and finally ran the
project in GlassFish and viewed the start page of the application in a browser.
These steps are always the first steps that we need to take when creating a new
PrimeFaces and JSF-based web application. Because of this, I felt that it's important
that the first chapter of this book is devoted to this rather than the more fun things
that we will be getting into later in the book.
[ 13 ]
www.PacktPub.com
Stay Connected: