AccordionPanel is a container component with vertically stacked panels.
<h:form id="form">
<p:growl id="msgs" showDetail="true" skipDetailIfEqualsSummary="true"/>
<div class="card">
<h5>Basic</h5>
<p:accordionPanel widgetVar="basic" scrollIntoView="center">
<p:tab title="Header I">
<p class="m-0">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum
dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
</p:tab>
<p:tab title="Header II">
<p class="m-0">
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab
illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut
odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Consectetur, adipisci velit, sed quia non numquam eius modi.
</p>
</p:tab>
<p:tab title="Header III">
<p class="m-0">At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores
et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga.
Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus.
</p>
</p:tab>
</p:accordionPanel>
</div>
<div class="card">
<h5>Multiple Selection</h5>
<p:accordionPanel multiple="true" widgetVar="multiple" scrollIntoView="center">
<p:tab title="Header I">
<p class="m-0">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum
dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
</p:tab>
<p:tab title="Header II">
<p class="m-0">
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab
illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut
odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Consectetur, adipisci velit, sed quia non numquam eius modi.
</p>
</p:tab>
<p:tab title="Header III">
<p class="m-0">At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores
et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga.
Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus.
</p>
</p:tab>
</p:accordionPanel>
</div>
<div class="card">
<h5>Options And Actions</h5>
<p:accordionPanel multiple="true" widgetVar="options" scrollIntoView="center" toggleSpeed="0">
<p:tab title="Header I">
<p class="m-0">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum
dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
</p:tab>
<p:tab title="Header III" menuTitle="Options">
<f:facet name="options">
<p:menu>
<p:submenu label="Options">
<p:menuitem value="Select all" url="#" icon="pi pi-clone" onclick="PF('options').selectAll()" />
<p:menuitem value="Unselect all" url="#" icon="pi pi-times" onclick="PF('options').unselectAll()" />
</p:submenu>
</p:menu>
</f:facet>
<p class="m-0">
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab
illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut
odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Consectetur, adipisci velit, sed quia non numquam eius modi.
</p>
</p:tab>
<p:tab title="Header III">
<f:facet name="actions">
<p:commandLink styleClass="ui-panel-titlebar-icon ui-corner-all ui-state-default">
<h:outputText styleClass="ui-icon pi pi-question" />
</p:commandLink>
<p:commandLink styleClass="ui-panel-titlebar-icon ui-corner-all ui-state-default">
<h:outputText styleClass="ui-icon pi pi-star" />
</p:commandLink>
</f:facet>
<p class="m-0">At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores
et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga.
Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus.
</p>
</p:tab>
</p:accordionPanel>
</div>
<div class="card">
<h5>On-Demand Loading</h5>
<p:accordionPanel dynamic="true" cache="true" multiple="true" widgetVar="ondemand">
<p:tab title="Header I">
<p class="m-0">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum
dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
</p:tab>
<p:tab title="Header II">
<p class="m-0">
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab
illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut
odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Consectetur, adipisci velit, sed quia non numquam eius modi.
</p>
</p:tab>
<p:tab title="Header III">
<p class="m-0">At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores
et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga.
Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus.
</p>
</p:tab>
</p:accordionPanel>
</div>
<div class="card">
<h5>Events and Validation</h5>
<p:accordionPanel>
<p:ajax event="tabChange" listener="#{tabbedView.onTabChange}" update=":form:msgs"/>
<p:ajax event="tabClose" listener="#{tabbedView.onTabClose}" update=":form:msgs"/>
<p:tab title="Validation">
<h:panelGrid columns="3" cellpadding="7" styleClass="mb-3">
<p:outputLabel for="firstname" value="Firstname:"/>
<p:inputText id="firstname" value="#{remoteValidationView.firstname}" required="true" label="Firstname">
<f:validateLength minimum="2"/>
</p:inputText>
<p:message for="firstname" display="icon"/>
<p:outputLabel for="lastname" value="Lastname:"/>
<p:inputText id="lastname" value="#{remoteValidationView.lastname}" label="Lastname" required="true">
<f:validateLength minimum="2"/>
<p:ajax update="msgLastname" event="keyup"/>
</p:inputText>
<p:message for="lastname" id="msgLastname" display="icon"/>
</h:panelGrid>
<p:commandButton value="Save" update="@form" action="#{remoteValidationView.save}" icon="pi pi-check"/>
</p:tab>
<p:tab title="Header II">
<p class="m-0">
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab
illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut
odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Consectetur, adipisci velit, sed quia non numquam eius modi.
</p>
</p:tab>
<p:tab title="Header III">
<p class="m-0">At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores
et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga.
Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus.
</p>
</p:tab>
</p:accordionPanel>
</div>
<div class="card product">
<h5>DataModel</h5>
<p:accordionPanel value="#{tabbedView.products}" var="product">
<p:tab title="#{product.name}">
<div class="product-list-item">
<p:graphicImage name="demo/images/product/#{product.image}"/>
<div class="product-list-detail">
<div class="product-name">#{product.name}</div>
<div class="product-description">#{product.description}</div>
<p:rating readonly="true" value="#{product.rating}"/>
<i class="pi pi-tag product-category-icon"/><span
class="product-category">#{product.category}</span>
</div>
<div class="product-list-action">
<h:outputText value="#{product.price}" styleClass="product-price">
<f:convertNumber currencySymbol="$" type="currency"/>
</h:outputText>
<span class="product-badge status-#{product.inventoryStatus.statusName}">#{product.inventoryStatus.text}</span>
</div>
</div>
</p:tab>
</p:accordionPanel>
</div>
</h:form>
package org.primefaces.showcase.view.panel;
import jakarta.annotation.PostConstruct;
import jakarta.enterprise.context.RequestScoped;
import jakarta.faces.application.FacesMessage;
import jakarta.faces.context.FacesContext;
import jakarta.inject.Inject;
import jakarta.inject.Named;
import java.util.List;
import io.quarkus.runtime.annotations.RegisterForReflection;
import org.primefaces.PrimeFaces;
import org.primefaces.event.TabChangeEvent;
import org.primefaces.event.TabCloseEvent;
import org.primefaces.showcase.domain.Product;
import org.primefaces.showcase.service.ProductService;
@Named
@RequestScoped
@RegisterForReflection(serialization = true)
public class TabbedView {
@Inject
ProductService service;
private List<Product> products;
@PostConstruct
public void init() {
products = service.getProducts(5);
}
public List<Product> getProducts() {
return products;
}
public void onTabChange(TabChangeEvent event) {
FacesMessage msg = new FacesMessage("Tab Changed", "Active Tab: " + event.getTab().getTitle());
FacesContext.getCurrentInstance().addMessage(null, msg);
}
public void onTabClose(TabCloseEvent event) {
FacesMessage msg = new FacesMessage("Tab Closed", "Closed tab: " + event.getTab().getTitle());
FacesContext.getCurrentInstance().addMessage(null, msg);
}
public void clearMultiViewState() {
FacesContext context = FacesContext.getCurrentInstance();
String viewId = context.getViewRoot().getViewId();
PrimeFaces.current().multiViewState().clearAll(viewId, true, this::showMessage);
}
private void showMessage(String clientId) {
FacesContext.getCurrentInstance()
.addMessage(null,
new FacesMessage(FacesMessage.SEVERITY_INFO, clientId + " multiview state has been cleared out", null));
}
}
package org.primefaces.showcase.view.ajax;
import jakarta.enterprise.context.RequestScoped;
import jakarta.faces.application.FacesMessage;
import jakarta.faces.context.FacesContext;
import jakarta.inject.Named;
import io.quarkus.runtime.annotations.RegisterForReflection;
@Named
@RequestScoped
@RegisterForReflection(serialization = true)
public class RemoteValidationView {
private String firstname;
private String lastname;
public String getFirstname() {
return firstname;
}
public void setFirstname(String firstname) {
this.firstname = firstname;
}
public String getLastname() {
return lastname;
}
public void setLastname(String lastname) {
this.lastname = lastname;
}
public void save() {
FacesContext.getCurrentInstance().addMessage(null,
new FacesMessage("Welcome " + firstname + " " + lastname));
}
}
package org.primefaces.showcase.domain;
import java.io.Serializable;
import java.util.List;
import io.quarkus.runtime.annotations.RegisterForReflection;
@RegisterForReflection
public class Product implements Serializable {
private int id;
private String code;
private String name;
private String description;
private String image;
private double price;
private String category;
private int quantity;
private InventoryStatus inventoryStatus;
private int rating;
private List<Order> orders;
public Product() {
}
public Product(int id, String code, String name, String description, String image, double price, String category, int quantity,
InventoryStatus inventoryStatus, int rating) {
this.id = id;
this.code = code;
this.name = name;
this.description = description;
this.image = image;
this.price = price;
this.category = category;
this.quantity = quantity;
this.inventoryStatus = inventoryStatus;
this.rating = rating;
}
@Override
public Product clone() {
return new Product(getId(), getCode(), getName(), getDescription(), getImage(), getPrice(), getCategory(), getQuantity(),
getInventoryStatus(), getRating());
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getImage() {
return image;
}
public void setImage(String image) {
this.image = image;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public String getCategory() {
return category;
}
public void setCategory(String category) {
this.category = category;
}
public int getQuantity() {
return quantity;
}
public void setQuantity(int quantity) {
this.quantity = quantity;
}
public InventoryStatus getInventoryStatus() {
return inventoryStatus;
}
public void setInventoryStatus(InventoryStatus inventoryStatus) {
this.inventoryStatus = inventoryStatus;
}
public int getRating() {
return rating;
}
public void setRating(int rating) {
this.rating = rating;
}
public List<Order> getOrders() {
return this.orders;
}
public void setOrders(List<Order> orders) {
this.orders = orders;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((code == null) ? 0 : code.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
Product other = (Product) obj;
if (code == null) {
return other.code == null;
} else {
return code.equals(other.code);
}
}
}
package org.primefaces.showcase.domain;
import java.util.Locale;
import io.quarkus.runtime.annotations.RegisterForReflection;
@RegisterForReflection
public enum InventoryStatus {
INSTOCK("In Stock"),
OUTOFSTOCK("Out of Stock"),
LOWSTOCK("Low Stock");
private final String text;
InventoryStatus(String text) {
this.text = text;
}
public String getText() {
return text;
}
public String getStatusName() {
return name().toLowerCase(Locale.ROOT);
}
}
package org.primefaces.showcase.domain;
import io.quarkus.runtime.annotations.RegisterForReflection;
@RegisterForReflection
public class Order implements java.io.Serializable {
private final int number;
private final String imagePath;
public Order(int number, String imagePath) {
this.number = number;
this.imagePath = imagePath;
}
public int getNumber() {
return number;
}
public String getImagePath() {
return imagePath;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Order order = (Order) o;
return number == order.number;
}
@Override
public int hashCode() {
return number;
}
}