O'Reilly logo

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

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 through AJAX

PrimeFaces' chart components support the itemSelect AJAX behavior event, which is fired when an item on the plotted data is clicked upon.

How to do it...

A simple definition for a bar chart, with a listener attached and two series of data to be displayed, is given as follows:

<p:barChart id="withAjax" value="#{barChartController.model}" style="height:250px">
  <p:ajax event="itemSelect" listener="#{barChartController.itemSelect}" update="growl" />
</p:barChart>

The listener is defined with the p:ajax component and will be called with the org.primefaces.event.ItemSelectEvent attribute.

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

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