PrimeFaces AccordionPanel – Dynamic Loading + Cache Example

If you’ve seen the primefaces accordion panel component, you are most probably asking about what’s the main important features that provided for the developer for making the component more useful. One of the feature is lazy loading of the content inside each tab.

AccordionPanel supports lazy loading of tab content, when dynamic attribute is set true, only active tab contents will be rendered to the client side and clicking an inactive tab header will do an ajax request to load the tab contents. This would increased the performance while first time rendering the page.

This feature is useful to reduce bandwidth and speed up page loading time. By default activating a previously loaded dynamic tab does not initiate to load the contents again as tab is cached. To control this behavior use cache option.

AccordionPanel tag has the attributes dynamic and cache for achieving the lazy loading and caching techniques. This tutorial highlights the benefits of those two attributes.

AccordionPanel Dynamic Loading

The below snapshots show you the impact of using dynamic attribute and the difference between considering it or not. Using dynamic attribute will load the activated panel data only. The remaining panels won’t be loaded any more until they are activated by the user. But if you provide no dynamic attribute the view does load the whole panels.

Running Without Dynamic Attribute

Running Demo without using dynamic attribute

  • Without using dynamic attribute, the all Accordion Tabs have activated.

Running With Dynamic Attribute

Running Demo using dynamic attribute

  • Using the dynamic attribute, wil cause the only first AccordionPanel Tab has been activated.
  • Considering that the other tabs will be activated once the user has clicked on.

AccordionPanel Data Cache

As mentioned previously, activating a previous loaded dynamic Tab doesn’t initiate a request to load the contents again as tab is cached. Disabling of cache attribute will solve this issue.

Running in Dynamic & Cached 

Accordion Dynamic & Cached

Running in Dynamic & Non Cached 

Accordion Dynamic & Non Cached

1. Managed Bean

package net.javabeat.primefaces;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

public class AccordionPanel {
	private String messageOne = "Hello JavaBeat One";
	private String messageTwo = "Hello JavaBeat Two";
	private String messageThree = "Hello JavaBeat Three";

	public String getMessageOne() {
		System.out.println("Message One Loaded");
		return messageOne;
	public void setMessageOne(String messageOne) {
		this.messageOne = messageOne;
	public String getMessageTwo() {
		System.out.println("Message Two Loaded");
		return messageTwo;
	public void setMessageTwo(String messageTwo) {
		this.messageTwo = messageTwo;
	public String getMessageThree() {
		System.out.println("Message Three Loaded");
		return messageThree;
	public void setMessageThree(String messageThree) {
		this.messageThree = messageThree;

2. index.xhtml

<html xmlns=""
		<script name="jquery/jquery.js" library="primefaces"></script>
		<h:form prependId="false">
			<h1>JavaBeat Primefaces Example</h1>
			<h2>Primefaces AccordionPanel</h2>
			<p:accordionPanel dynamic="true" cache="false">
				<p:tab title="First Tab Title">
					<h:outputText value="#{accordionPanel.messageOne}"></h:outputText>
				<p:tab title="Second Tab Title">
					<h:outputText value="#{accordionPanel.messageTwo}"></h:outputText>
				<p:tab title="Third Tab Title">
					<h:outputText value="#{accordionPanel.messageThree}"></h:outputText>

3. Faces Configuration File


<?xml version="1.0" encoding="UTF-8"?>
<faces-config xmlns=""

4. Pom.xml File


<!--Pom entries-->







<!--Pom entries-->

Leave a Reply

Your email address will not be published. Required fields are marked *

Pin It on Pinterest

Share This

Share this post with your friends!