O'Reilly logo

PrimeFaces Cookbook - Second Edition by Oleg Varaksin, Mert Çalışkan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Interacting with charts via AJAX

The chart component offers AJAX behavior events to interact with the chart by item selection.

How to do it…

A basic definition for a chart with <p:ajax> bundled inside is given here:

<p:chart type="bar" id="withAjax" model="#{chartBean.barModel}"
  style="height:250px">
  <p:ajax event="itemSelect" listener="#{chartBean.itemSelect}"
    update="growl" />
</p:chart>

The itemSelect method retrieves an instance of org.primefaces.event.ItemSelectEvent, which enables us to access the item index and series index of the selected chart item. The usage of the itemSelect method is given here:

public void itemSelect(ItemSelectEvent event) { MessageUtil.addInfoMessageWithoutKey("Item selected", "Item Index:" + event.getItemIndex() + ", ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required