Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
PrimeFaces Cookbook
PrimeFaces Cookbook

PrimeFaces Cookbook: Here are over 100 recipes for PrimeFaces, the ultimate JSF framework. It's a great practical introduction to leading-edge Java web development, taking you from the basics right through to writing custom components.

eBook
€19.99 €28.99
Paperback
€37.99
Subscription
Free Trial
Renews at €18.99p/m

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
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

PrimeFaces Cookbook

Chapter 2. Theming Concept

In this chapter we will cover:

  • Understanding structural and skinning CSS

  • Installing themes

  • Customizing theme styles

  • Customizing default styles on input components

  • Adjusting the font and size throughout the web application

  • Why does the theme look different in Internet Explorer?

  • Simple ways to create a new theme

  • Default stateless theme switcher

  • Alternative stateful theme switchers

Introduction


In this chapter, readers will be introduced to PrimeFaces themes and the concepts involved. Later on, we will build on these concepts to learn the theming of the PrimeFaces components. The theming concept used in PrimeFaces is similar to the jQuery ThemeRoller CSS Framework (http://jqueryui.com/themeroller). All PrimeFaces components are designed to allow a developer to integrate them seamlessly into the look and feel of an entire web application. At the time of writing, there are 35 plus ready-to-use themes, which you can preview and download from the PrimeFaces theme gallery (http://primefaces.org/themes.html).

Powered by ThemeRoller, PrimeFaces separates structural CSS from skinning CSS. The difference between the two CSS concepts is the topic of the first recipe. Installation and customization of PrimeFaces themes along with creation of new themes will be detailed. We will also see how to adjust the font family and font size throughout the PrimeFaces components .Adapted...

Understanding the structural and skinning CSS


Each component is styled with CSS and contains two layers of style information—structural or component-specific and skinning or component-independent styles.

In this recipe, you will understand the difference between these two types of CSS, learn some useful selectors, and see an exemplary styling of the PickList component in the generated HTML.

Getting ready

To learn about different layers of style information, you can go to the PrimeFaces ShowCase (http://primefaces.org/showcase/ui/home.jsf) and look at it in the Firefox browser with an installed Firebug add-on (http://getfirebug.com). Firebug allows live editing, debugging, and monitoring CSS, HTML, and JavaScript in any web page. The add-on can be opened after its installation by navigating to Tools | Web Developer | Firebug or by pressing the F12 key. Another useful tool is built-in Developer Tools for the Google Chrome browser, which is similar to the Firebug.

How to do it...

Go to the...

Installing themes


PrimeFaces themes are bundled as JAR files and available for download at the PrimeFaces repository (http://repository.primefaces.org/org/primefaces/themes). Each theme can be quickly previewed before download at PrimeFaces Theme Gallery (http://primefaces.org/themes.html) or tested in the PrimeFaces ShowCase with an integrated theme switcher.

In this recipe, we will install and configure themes to use them in an JSF application. The steps to accomplish this task are straightforward.

Getting ready

If you are a Maven (http://maven.apache.org) user, ensure that you have Maven installed. Maven is a build and project management tool, which manages installation of all dependencies in an easy way. PrimeFaces is a Maven-based project and offers all artifacts, including themes, as Maven dependencies.

How to do it...

Maven users should define any desired theme artifact in their project's pom.xml as follows:

<dependency>
  <groupId>org.primefaces.themes</groupId>
  &lt...

Customizing theme styles


How to customize theme styles is one of the most asked questions by the PrimeFaces users. There are simple rules to be followed to overwrite bundled theme styles with custom CSS. There is no need to edit bundled themes and repackage theme JAR files.

In this recipe, we will present two examples for theme customization—one for SelectOneMenu and another for the Tree component. We will see how to change styles for a particular component or for all components of the same type. Furthermore, we will learn tips for where to place custom CSS in order to overwrite the PrimeFaces styles.

How to do it...

Let's set a fixed width for p:selectOneMenu and remove the background and border for p:tree. The default width of p:selectOneMenu is calculated at runtime. That means, the width of p:selectOneMenu is dynamic and depends on its content (select items). Large select items cause large p:selectOneMenu. A fixed width would show a better (from visual point of view) p:selectOneMenu for...

Customizing default styles on input components


Customizing default styles on input components is a special task often asked about by the PrimeFaces users. They also ask for a recommended method for removing styles on form components. The reason to do that can be a company style guide and corporate identity throughout all applications.

In this recipe, we will find out a way to customize the PrimeFaces styles on input components and see if it is possible at all to disable theming on such components.

How to do it...

We will develop two groups of components having input elements. The first group is styled with the PrimeFaces default styles (here the Home theme). The second one has a custom styling. We have removed the border, background, shadow, and round corners on them. Furthermore, we have changed the styling of disabled inputs. Disabled elements get assigned the ui-state-disabled style class, so that we can adjust it as we want. Generally, to distinguish between input and non-input elements...

Adjusting the font and size throughout the web application


Each PrimeFaces theme has a specific font family and font size, which can be different from theme to theme. This may have a disadvantage in a multi-theme application because switching from one theme to another would cause a broken layout. Furthermore, default font sizes of themes might be bigger than expected. Hence, it is important to know how to change font properties of the PrimeFaces components globally.

In this recipe, we will learn how to adjust the font family and font size throughout the web application.

How to do it...

A simple way to change fonts globally can be accomplished by using the .ui-widget style class. An example of smaller font is as follows:

.ui-widget, .ui-widget .ui-widget {
    font-size: 90% !important;
}

This might not be enough in some cases, especially when you mix PrimeFaces and JSF standard components based on native HTML pendants. In this case, more CSS selectors are required to be listed in order to adjust...

Why does the theme look different in Internet Explorer?


Themable components look different in Internet Explorer 7 and 8, and browsers such as Google Chrome, Safari, or Firefox. There is a reason for that, which will be explained in this recipe. The main question is, do we need to take care of that? An update to Internet Explorer 9 or higher would be enough, but it is not always possible by reason of supporting web applications running in "old" browsers or due to some company-wide restrictions.

In this recipe, we will see if there are any ways to overcome this issue.

How to do it...

PrimeFaces does not officially support Internet Explorer 6. Internet Explorer 7 and 8 do not implement rounded corners, gradients, and advanced CSS3 effects. They do not follow CSS standards the same way as modern browsers or do not implement the latest CSS specifications. As a result, pages with themes like "Aristo", "Afterdark", or "Afternoon" look different in Internet Explorer 7 and 8—no round corners, no CSS3...

Simple ways to create a new theme


We sometimes need to create our own themes instead of using the pre-defined ones. Web applications should often feature a company-specific look and feel, which is constant and preset by company-wide style guides. Creating new themes is easy with PrimeFaces because it is powered by the ThemeRoller CSS framework (http://jqueryui.com/themeroller). ThemeRoller provides a powerful and easy-to-use online visual tool.

In this recipe, we will go on systematically and show all needed steps to create a new theme.

Getting ready

To gain first-hand experience with the ThemeRoller online visual tool, go to the ThemeRoller home page, explore the available theme Gallery, and play with the CSS properties to see changes for jQuery widgets embedded on the page. All CSS changes will be applied on the fly.

How to do it...

The simplest way to make our own theme is to modify one of the existing PrimeFaces themes. Choose one from the PrimeFaces Theme Gallery (http://primefaces.org/themes...

Default stateless theme switcher


Multi-themable web applications require a theme switcher component. The default PrimeFaces' theme switcher is a component, which enables switching themes on the fly without a round-trip to the server. We speak about a stateless theme switcher because the current selected theme is only known on the client side.

In this recipe, we will show the usage of such a stateless theme switcher.

How to do it...

The theme switcher usage is very similar to the usage of p:selectOneMenu. The component is represented by the p:themeSwitcher tag and accepts f:selectItem or f:selectItems.

<p:themeSwitcher style="width:165px" effect="fade">
    <f:selectItem itemLabel="Choose Theme" itemValue=""/>
    <f:selectItems value="#{userSettingsController.themes}"/>
</p:themeSwitcher>

Themes are prepared in a managed bean UserSettingsController.

@ManagedBean
@SessionScoped
public class UserSettingsController implements Serializable {

    public Map<String, String...

Alternative stateful theme switchers


By default, PrimeFaces theme switcher only changes the theme on the fly without sending an AJAX or full-page request. Users often want to get notified when the current theme has been changed in order to be able to update user preferences or settings.

In this recipe, we will implement two stateful theme switchers, which are able to save the current selected theme on the server side.

How to do it...

The next listing demonstrates a stateful theme switcher with attached AJAX behavior.

<p:themeSwitcher id="statefulSwitcher1" 
                 value="#{userSettingsController.theme}"
                 style="width:165px" effect="fade">
    <f:selectItem itemLabel="Choose Theme" itemValue=""/>
    <f:selectItems value="#{userSettingsController.themes}"/>
    <p:ajax listener="#{userSettingsController.saveTheme}"/>
</p:themeSwitcher>

Another advanced theme switcher supports displaying theme previews in the form of small images.

We can develop...

Left arrow icon Right arrow icon

Key benefits

  • The first PrimeFaces book that concentrates on practical approaches rather than the theoretical ones
  • Readers will gain all the PrimeFaces insights required to complete their JSF projects successfully
  • Written in a clear, comprehensible style and addresses a wide audience on modern, trend-setting Java/JEE web development

Description

PrimeFaces is the de facto standard in the Java web development. PrimeFaces is a lightweight library with one jar, zero-configuration, and no required dependencies. You just need to download PrimeFaces, add the primefaces-{version}.jar to your classpath and import the namespace to get started. This cookbook provides a head start by covering all the knowledge needed for working with PrimeFaces components in the real world. "PrimeFaces Cookbook" covers over 100 effective recipes for PrimeFaces 3.x which is a leading component suite to boost JSF applications. The book's range is wide‚Äí from AJAX basics, theming, and input components to advanced usage of datatable, menus, drag & drop, and charts. It also includes creating custom components and PrimeFaces Extensions.You will start with the basic concepts such as installing PrimeFaces, configuring it, and writing a first simple page. You will learn PrimeFaces' theming concept and common inputs and selects components. After that more advanced components and use cases will be discussed. The topics covered are grouping content with panels, data iteration components, endless menu variations, working with files and images, using drag & drop, creating charts, and maps. The last chapters describe solutions for frequent, advanced scenarios and give answers on how to write custom components based on PrimeFaces and also show the community-driven open source project PrimeFaces Extension in action.

Who is this book for?

This book is for you if you would like to learn modern Java web development based on PrimeFaces and are looking for a quick introduction into this matter. Prerequisites required for this book are basic JSF and jQuery skills.

What you will learn

  • Learn basic concepts to be able to work with PrimeFaces.
  • Delve deep into 100+ rich UI components with all the required details
  • Get solutions to typical and advanced use cases
  • Use the best practices, avoid pitfalls, and get performance tips when working with the component suite
  • Gain know-how of writing custom components on basis of the PrimeFaces core functionality
  • Meet additional components from the PrimeFaces Extensions

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Jan 22, 2013
Length: 328 pages
Edition : 1st
Language : English
ISBN-13 : 9781849519298
Languages :

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
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Jan 22, 2013
Length: 328 pages
Edition : 1st
Language : English
ISBN-13 : 9781849519298
Languages :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
€189.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
€264.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 79.98
PrimeFaces Beginner's Guide
€41.99
PrimeFaces Cookbook
€37.99
Total 79.98 Stars icon

Table of Contents

10 Chapters
Getting Started with PrimeFaces Chevron down icon Chevron up icon
Theming Concept Chevron down icon Chevron up icon
Enhanced Inputs and Selects Chevron down icon Chevron up icon
Grouping Content with Panels Chevron down icon Chevron up icon
Data Iteration Components Chevron down icon Chevron up icon
Endless Menu Variations Chevron down icon Chevron up icon
Working with Files and Images Chevron down icon Chevron up icon
Drag Me, Drop Me Chevron down icon Chevron up icon
Creating Charts and Maps Chevron down icon Chevron up icon
Miscellaneous, Advanced Use Cases Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.3
(17 Ratings)
5 star 23.5%
4 star 17.6%
3 star 29.4%
2 star 23.5%
1 star 5.9%
Filter icon Filter
Top Reviews

Filter reviews by




SuJo Jan 20, 2014
Full star icon Full star icon Full star icon Full star icon Full star icon 5
[...] - Pact Pub LinkAfter reading this book over the past week I have a clearer understanding about Java technology for web development; I've used an Instant PrimeFaces eBook from Pact awhile back and it was superb, and this was just the icing on the cake. I knew little about Java but after reading this and applying a few of the principles in sample applications I can say it was well wroth it. Everything was organized and it was incredibility easy to get up and running fast. Starting from the first chapter until the last it kept my attention and I was really impressed by all the different widgets and even how you can theme your design using PrimeFaces. I've used other API/Frameworks and this has always been one of my top favorites.This book is geared for anyone from beginner to professional and going in as a beginner I really enjoyed this book, I encourage you to give it a go as it won't be disappointing.
Amazon Verified review Amazon
Alessandro Garrido Milani May 10, 2016
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Nice
Amazon Verified review Amazon
Paulo N Carrillo Peña Aug 16, 2013
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I love this book because i found many details that i was looking on primefaces website...I'm a Java developer and primefaces is quite beautiful to develop with, but there are some details that are explained on this book that helps you to solve some problems
Amazon Verified review Amazon
Stanislav Feb 23, 2013
Full star icon Full star icon Full star icon Full star icon Full star icon 5
It's really helps me to solve a lot of difficult tasks in my project, based on Java Server Faces 2 and PrimeFaces 3.4.2.There should be much more such books for fellows, like me. Very, very useful. Afftar, pishi ischo.
Amazon Verified review Amazon
Renato Stalder Mar 17, 2013
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
Gute Zusammenfassung der PrimeFaces Möglichkeiten. An manchen Stellen geht das Buch nicht tief genug. Um aber schnell damit starten zu können, ist es ein idealer Einstieg.
Amazon Verified review Amazon
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.