Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Primefaces Theme development
Primefaces Theme development

Primefaces Theme development: Create, package, and customize stunning themes using PrimeFaces

$29.99 $20.98
Book Nov 2015 224 pages 1st Edition
eBook
$29.99 $20.98
Print
$38.99
Subscription
$15.99 Monthly
eBook
$29.99 $20.98
Print
$38.99
Subscription
$15.99 Monthly

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Buy Now

Product Details


Publication date : Nov 3, 2015
Length 224 pages
Edition : 1st Edition
Language : English
ISBN-13 : 9781783988686
Vendor :
PrimeFaces
Category :
Table of content icon View table of contents Preview book icon Preview Book

Primefaces Theme development

Chapter 1. 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:

  • Why we need to create an app

  • An introduction to the PrimeFaces library

  • Creating a Maven JSF project

  • Integrating the PrimeFaces library into a Maven JSF project

  • Adding the additional dependencies that GlassFish needs

  • Building the project

  • Running the project

Why we need to create an app


Although this book is about developing PrimeFaces themes, we will need a web application to actually test our designs. Also, a web application will be used to show how to integrate PrimeFaces into a web application and how components such as ThemeSwitcher are used in practice to allow a user to select their themes. Because of this, we will spend some time at the beginning creating and adding a web application to a Maven-based NetBeans project. When we start creating and using our own themes, the work that we will have done here will make it far easier to appreciate our creative efforts there.

The PrimeFaces library


While looking for a suitable set of Open Source (OS) JSF components several years ago, I discovered PrimeFaces almost by accident. What I found was a link to the PrimeFaces showcase. I was immediately impressed by the number of components that it offered and the fact that skins or themes were supported out of the box. Also, PrimeFaces uses industry-standard libraries such as jQuery and jQuery UI to make things work well and look good too. Because PrimeFaces uses the JSF standard extension framework, there are no headaches involved in integrating it into new or existing projects. In addition to providing a set of JSF components, it also provides a complete set of data model classes to support the various data-oriented components and some very useful utility classes as well. Last, but not least, PrimeFaces offers WebSocket support by integrating the excellent Atmosphere WebSocket library.

PrimeFaces also has a very active forum community, where I am often found answering questions asked by users, and hopefully getting them right too.

The version of PrimeFaces that I first used was 2.2, and at the time of writing this book, PrimeFaces has reached release 5.2, with 5.3 in the pipeline. The team of developers has done a wonderful job providing us with, in my opinion, the best OS JSF component library out there. It is worth paying a visit to the showcase at http://www.primefaces.org/showcase/, especially now that it has had a face lift and the very capable components are shown off in all their glory.

Creating a NetBeans Maven JSF project


After launching NetBeans, open the File menu and select New Project from the available project types. Locate and select Maven. A list of Maven archetypes (project templates) is available. Select Web Application, as shown in the following screenshot:

Click on Next and the following screenshot appears:

Project Name is set to PFThemes.

Project Location is generated automatically and it does not need to be changed.

The following Maven properties are listed:

  • Artifact Id: This cannot be changed. It is the name of your project.

  • Group Id: This can be edited as required. This sets the base package for the project.

  • Version: This does not need to be changed.

  • Project: This is the last property that we will use to set the root package for all the Java classes in the project.

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:

I chose GlassFish because it is the Java EE reference implementation. I selected GlassFish Server 4.0 because this is the current release version of GlassFish and the nightly builds are available to me.

Tip

You can use any Java EE 7 container that supports the Java EE 7 web profile that you like. The list of potential servers is long, but Tomcat (http://tomcat.apache.org/), TomEE (http://tomee.apache.org/), and WildFly (http://wildfly.org/) are suitable ones. Tomcat and TomEE are freely available from the Apache Software Foundation (http://apache.org/)and WildFly is available from RedHat.

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.

Note

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:

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:

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.

Tip

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.

Once you have set up the JSF framework to your satisfaction, click on OK, and the changes will be applied to our project.

Tip

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.

Adding the PrimeFaces library and related dependencies to our project


We will use Maven to add all the required resources that we don't create ourselves, and this section will help us to understand how we add libraries to our project. PrimeFaces only requires that the PrimeFaces JAR file be added to our project. So, this is what we do:

  1. By clicking on the + symbol to the left of the project in the Project view, we open the project tree, as follows:

    The following is a brief explanation of the folders, as listed in the previous screenshot:

    • Web Pages: This is where we will add views or pages to our application.

    • Source Packages: Here, Java source code is managed.

    • 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.

    • Dependencies: Here we tell Maven the JAR files that we want to add to our project.

    • Runtime Dependencies and Java Dependencies: These are not important for this project. Feel free to browse them at your leisure.

    • Project Files: This is where NetBeans manages both the Maven project's pom.xml file and the NetBeans project configuration file. While we don't need to look at these now, we will visit the pom.xml file in the later chapters. So, if you want to preview these files, please feel free to do so.

  2. Meanwhile, we are going to add PrimeFaces 5.2 to our project. Right-click on the Dependencies folder and select Add Dependency... from the context menu. This opens the Add Dependency dialog box, as shown in the following screenshot:

    Usually, you only have the Search tab available in a newly created project.

    Tip

    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.

    Tip

    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:

  4. Select the 5.2 version and click on Add. Maven then adds the dependency to our project.

Building the project


When we build the project, Maven will cause the required file to be downloaded and added to our local Maven repository. It will copy the file into the WEB-INF/lib folder of the build target.

If we right-click on the project and select Build, Maven will do its magic. When it is finished, we can use the Files view to see the result. Click on the Files tab. Then open the project tree view. You will see an src and a target folder, as well as the project's pom.xml file and the NetBeans project configuration files.

Open the target folder. Then expand the PFThemes-1.0-SNAPSHOT folder. As we are confident that the build process will have worked correctly, we can now see the structure of the web application:

Tip

The Java EE 7 standard mandates a formal folder structure for web applications. The META-INF and WEB-INF folders are where application-specific resources are stored. Under WEB-INF, you will see a classes folder, a lib folder, and several configuration files. Don't worry if you don't see any or all of the configuration files. Only web.xml is generated by default; the others will be created later in this chapter. The classes folder is to where Java classes are compiled. The lib folder is where JAR files, such as the PrimeFaces JAR file, are added.

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.

Running the project


Now build the project again. After the build is finished, right-click on the project and select Run.

This causes the GlassFish server to run and our application to be deployed. Once the project is deployed, NetBeans then opens its default browser and points it to the application's start page.

Tip

I use Google Chrome as my NetBeans default browser because NetBeans provides a Chrome plugin that allows us to debug scripts in our pages as well as other useful services. I am not going to force you to use a particular browser, but I do recommend that you use Google Chrome for the aforementioned reasons. The only browser-related thing that you should avoid is using Internet Explorer below version 8. The latest JSF technologies are not guaranteed to work with the older Internet Explorer versions, and the visual experience, even with Internet Explorer 8, is underwhelming compared to modern browsers.

We should see something like this in Chrome:

Now that we have got the project running, we can add the other configuration files that we saw in an earlier screenshot.

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.

Left arrow icon Right arrow icon

Key benefits

  • • Build PrimeFaces themes that meet the industry standards
  • • Customize your themes for mobile web applications with PrimeFaces Mobile
  • • A precise, example-oriented guide to help you create interesting themes using the PrimeFaces tools

Description

Developing stunning themes for web applications has never been easier! PrimeFaces delivers a powerful set of features that enables JSF developers to create and customize awesome themes on the web. It is very easy to use because it comes as a single JAR file and requires no mandatory XML configuration. With more than 30 out-of-the-box themes, jQuery integration, a mobile UI toolkit, Ajax Push technology, and much more, PrimeFaces takes JSF application development to a whole new level! This book is a hands-on example-rich guide to creating and customizing PrimeFaces themes using available tools. Beginning with creating a JSF project and integrating the PrimeFaces library, this book will introduce you to the features of theme components, how these are structured, and how PrimeFaces uses JQuery UI to apply a theme to your application. You will learn to examine and change the CSS rules and get creative by setting standard icons and adding new icons to them. You will use a combination of JavaScript and CSS to enhance your application with help of scheduler component and go on to adapt and package your custom theme so that it is compatible with the Resource Manager. Finally, you will explore PrimeFaces mobile apps, ensuring themes are compatible with your mobile applications best practices for theme design.

What you will learn

• Use Maven to create JSF Projects • Create a custom theme using JQuery UI tools • Package your theme for distribution and use your PrimeFaces-based web applications as drop in libraries. • Develop additional dynamic look and feel elements that themes do not already supply • Apply look and feel elements dynamically to views without causing page refreshes • Reduce code repetition by applying page templates to your JSF project

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Buy Now

Product Details


Publication date : Nov 3, 2015
Length 224 pages
Edition : 1st Edition
Language : English
ISBN-13 : 9781783988686
Vendor :
PrimeFaces
Category :

Table of Contents

18 Chapters
PrimeFaces Theme Development Chevron down icon Chevron up icon
Credits Chevron down icon Chevron up icon
About the Authors Chevron down icon Chevron up icon
About the Reviewers Chevron down icon Chevron up icon
www.PacktPub.com Chevron down icon Chevron up icon
Preface Chevron down icon Chevron up icon
To Skin an App Chevron down icon Chevron up icon
Introducing PrimeFaces Themes Chevron down icon Chevron up icon
jQuery UI, ThemeRoller, and the Anatomy of a Theme Chevron down icon Chevron up icon
A PrimeFaces inputText Component in Detail Chevron down icon Chevron up icon
Let's Get Creative Chevron down icon Chevron up icon
Icons Chevron down icon Chevron up icon
Dynamic Changes – a Working Example Chevron down icon Chevron up icon
Mobile Web Apps Chevron down icon Chevron up icon
The Final Touches Chevron down icon Chevron up icon
Theme Design Best Practices Chevron down icon Chevron up icon
Premium Themes and Layouts, and Third-party Converter Tools Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Filter icon Filter
Top Reviews
Rating distribution
Empty star icon Empty star icon Empty star icon Empty star icon Empty star icon 0
(0 Ratings)
5 star 0%
4 star 0%
3 star 0%
2 star 0%
1 star 0%

Filter reviews by


No reviews found
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.