Book Image

PrimeFaces Cookbook

Book Image

PrimeFaces Cookbook

Overview of this book

Table of Contents (20 chapters)
PrimeFaces Cookbook Second Edition
Credits
Foreword
Foreword
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

The context menu with nested items


The context menu is displayed when the mouse is right-clicked. It replaces the native context menu in the browser and gives web applications a desktop-like feel and behavior. PrimeFaces' context menu provides an overlay with submenus and menu items.

In this recipe, we will develop a context menu with nested items and see how to attach it to any component. For example, we will attach the context menu to a panel component.

How to do it…

The context menu is defined by the p:contextMenu tag. We would like to define two submenus—one with menu items having URLs (they send GET requests) and one with AJAX-ified menu items (they send POST requests). AJAX-ified menu items perform the CRUD operations and update p:growl. The context menu is attached to p:panel. That means only a right-click on the panel component displays the defined context menu. A click anywhere else displays the native web browser's context menu. This is shown in the following code:

<p:growl id=...