Book Image

Primefaces Theme development

Book Image

Primefaces Theme development

Overview of this book

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.
Table of Contents (18 chapters)
PrimeFaces Theme Development
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

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 mobile-based 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.

What this book covers

Chapter 1, To Skin an App, covers how to create a JSF project and integrate the PrimeFaces library into it. The chapter is meant to bring all the readers onto a level playing field and provide a platform from which both the book and a PrimeFaces theme can be built.

Chapter 2, Introducing PrimeFaces Themes, compares the standard JSF and PrimeFaces components and highlights that JSF does not provide for theming by itself, but it does provide mechanisms to extend the capabilities of the framework to include themes and a rich set of components.

Chapter 3, jQuery UI, ThemeRoller, and the Anatomy of a Theme, explains how at theme is structured and how PrimeFaces uses jQuery UI to apply a theme to your application.

Chapter 4, A PrimeFaces inputText Component in Detail, takes a simple UI component and uses browser developer tools to examine and change the CSS rules applied to it. In this chapter, we will strip away some of the mysteries involved in applying a Theme to your application.

Chapter 5, Let's Get Creative, builds on the work in the previous chapter by using a custom theme and tweaking it according to our needs. This will expose some of the weaknesses of ThemeRoller-generated themes and how to compensate for them.

Chapter 6, Icons, explains the role of icons in the PrimeFaces web application by using icons from the standard theme icon set, creating custom icons, and applying them on some PrimeFaces components for demonstration purposes. This chapter also introduces the Font Awesome icons apart from the regular ThemeRoller icons.

Chapter 7, Dynamic Changes – a Working Example, explores how to use a combination of JavaScript and CSS to enhance an application. Themes can only do so much and quite often, we want to enhance the way a PrimeFaces component looks like depending on the state of the underlying data.

Chapter 8, Mobile Web Apps, talks about PrimeFaces Mobile and how to create customized mobile themes using ThemeRoller and apply a customized mobile theme that is suitable for mobile web applications.

Chapter 9, The Final Touches, explains how to make sure that the newly created desktop/mobile theme is complete by applying it to the PrimeFaces showcase application and performing the common component-specific CSS modifications to finalize the theme JAR files according to users' interests.

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.

What you need for this book

As a JSF developer, you should already have in-depth knowledge of general Java programming, JSF and/or Java EE 6 or 7, (X)HTML, CSS, and JavaScript. In addition to this, a familiarity with the PrimeFaces component library will be of help when reading and working through the examples in the book. A working knowledge of Maven will also be of help.

The following are the additional requirements for this book:

  • Recommended JSF: Java 7

  • Recommended IDE: NetBeans 8

  • Recommended web server: Glassfish 4

  • The PrimeFaces version being used is freely available PrimeFaces 5.2

  • A fork of the Git-based Project accompanies this book

If you already have ideas for a custom theme, then you will have an even more enjoyable time in the later chapters.

The most important thing that you will need is a desire to be creative when designing web applications. A well-thought-out look and feel of an application is what gives your users the best first impression. These impressions are the ones that are the strongest and most lasting.

You will need the following additional resources as well:

  • PrimeFaces website

  • jQuery and jQuery UI

  • CSS reference

Because we don't want to enter the debate about which browser is the best and why others shouldn't be used, the choice of browser is up to you. I prefer using Google Chrome because of its developer tools as well as for more mundane reasons. The only requirement is that it supports CSS3, HTML5, and JavaScript and has a tool for the examination and changing of DOM elements on the fly. The screenshots in this book will show me using Google Chrome.

Who this book is for

This book is for the following two main audiences:

  • Web designers who need or are interested in an introduction to PrimeFaces, with an emphasis on theme development

  • JSF/Java EE developers who are mainly responsible for middle and backend component development but who either need to know more about the UI, especially using PrimeFaces, or who are keen to expand their knowledge of how it all works.

The book is also aimed at anyone who is interested in JSF because with JSF, it is easy for non-UI specialists to create user interfaces and with PrimeFaces, it is easy to build them with a good look and feel from the word go. The book explains how PrimeFaces themes work and, more importantly, provides insights into how to create custom themes.

Conventions

In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "Fortunately, the schedule component provides a simple client-side API, which includes the update() method to save the bandwidth and increase the page load performance."

A block of code is set as follows:

<h:form id="mainform">
  <h:panelGrid id="maintable" columns="2">
    <h:outputLabel id="simpleLabel1" value="A standard inputText component:" for="standardInput"/>
    <h:inputText id="standardInput"/>
    <p:outputLabel id="pfLabel2" value="A PrimeFaces inputText component:" for="pfInput"/>
    <p:inputText id="pfInput"/>
  </h:panelGrid>
</h:form>

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

<p:submenu id="chapter2" label="Chapter 2">
  <p:menuitem id="c2difference" value="Differences" url="/chapter2/difference.xhtml"/>
  <p:menuitem id="c2morecomponents" value="Mini Showcase" url="/chapter2/morecomponents.xhtml"/>
</p:submenu>

Any command-line input or output is written as follows:

git clone https://github.com/primefaces/showcase.git

New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "Choose the file or drag and drop the ThemeRoller theme in the ZIP format and click on the create theme jar button."

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply send an e-mail to , and mention the book title via the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

All the projects or source code for this book are available in the GitHub repository. You can download it from the following link: https://github.com/andyba/PFThemes

Downloading the color images of this book

We also provide you a PDF file that has color images of the screenshots/diagrams used in this book. The color images will help you better understand the changes in the output. You can download this file from: https://www.packtpub.com/sites/default/files/downloads/8686OS_ColoredImages.pdf.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the errata submission form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded on our website, or added to any list of existing errata, under the Errata section of that title. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support.

Piracy

Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors, and our ability to bring you valuable content.

Questions

You can contact us at if you are having a problem with any aspect of the book, and we will do our best to address it.