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

Integrating the context menu


Data iteration components, such as dataTable, tree, and treeTable, have a special integration with the context menu. These components can display a context menu for every right-click of the mouse on any row in dataTable or any node in tree.

In this recipe, we will integrate a context menu with the tree component. Integration with dataTable or treeTable is similar and described well in the PrimeFaces User's Guide documentation (http://primefaces.org/documentation.html).

How to do it…

We will develop a context menu with two menu items—View and Delete. A View item shows the currently selected tree node, and the Delete item removes it. We would like to implement this behavior for all tree nodes. The following listing demonstrates the integration of p:contextMenu with p:tree:

<p:growl id="growl" showDetail="true"/>

<p:contextMenu for="fileSystem">
  <p:menuitem value="View" update="growl"
    actionListener="#{contextMenuBean.viewNode}"
    icon="ui-icon...