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
$48.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
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 : 9781849519281
Languages :

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

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

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.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
$199.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
$279.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 $ 103.98
PrimeFaces Beginner's Guide
$54.99
PrimeFaces Cookbook
$48.99
Total $ 103.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

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.