Breadcrumb – providing contextual information about page hierarchy

Breadcrumb is a navigation component that provides contextual information about the page hierarchy. It allows users to keep track of their locations within the workflow.

In this recipe, we will develop a simple breadcrumb with a handy configuration attribute.

How to do it…

The breadcrumb component is represented as the p:breadCrumb tag with nested menu items. We will use the same CDI bean as in the Statically and dynamically positioned menus recipe of this chapter. This is shown in the following code:

<p:breadCrumb>
  <p:menuitem value="PrimeFaces" url="http://primefaces.org"/>
  <p:menuitem value="jQuery" url="http://jquery.com"/>
  <p:menuitem value="Yahoo UI" url="http://yuilibrary.com"/>
  <p:menuitem value="Save"
    actionListener="#{positionedMenuBean.save}"
    update="growl"/>
  <p:menuitem value="Update"
    actionListener="#{positionedMenuBean.update}"
    update="growl"/>
</p:breadCrumb>

A "home page" icon is shown at the root link, but display of text is possible too. The following code shows this:

<p:breadCrumb homeDisplay="text">
  ...
</p:breadCrumb>

The next image demonstrates these two cases:

How to do it…

How it works…

Single items within p:breadCrumb are defined as p:menuitem. You can either set the url attribute to navigate to another page or define action/actionListener to invoke a server-side method.

The appearance of the root link is controlled by the homeDisplay attribute. It is set to the icon value by default. Setting homeDisplay="text" will display the text instead of the icon.

There's more…

A breadcrumb can be created programmatically as well. This approach is described in the Creating programmatic menus recipe of this chapter.

PrimeFaces Cookbook Showcase application

This recipe is available in the demo web application on GitHub (https://github.com/ova2/primefaces-cookbook/tree/second-edition). Clone the project if you have not done it yet, explore the project structure, and build and deploy the WAR file on application servers compatible with Servlet 3.x, such as JBoss WildFly and Apache TomEE.

The showcase for the recipe is available at http://localhost:8080/pf-cookbook/views/chapter6/breadcrumb.jsf.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.218.97.75