OverlayPanel is a generic container component that can overlay other components on page. Notable features are custom positioning, configurable events and effects. Lazy content loading to reduce page load time is also supported via dynamic option, when enabled overlayPanel will load the contents just before being shown.
<div class="card">
<h:form id="form">
<h5>Basic</h5>
<p:commandButton id="basic" value="Show" type="button"/>
<p:overlayPanel for="basic" style="width:350px">
<p>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:overlayPanel>
<h5>Images</h5>
<p:commandButton id="images" type="button" icon="pi pi-image" />
<p:overlayPanel for="images" dismissable="false" showCloseIcon="true">
<p:imageSwitch effect="fade">
<ui:repeat value="#{imageSwitchView.images}" var="image">
<p:graphicImage name="/demo/images/nature/#{image}"/>
</ui:repeat>
</p:imageSwitch>
</p:overlayPanel>
<h5>SplitButton</h5>
<p:splitButton id="split" value="SplitButton">
<p:overlayPanel style="width:350px">
<p>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:overlayPanel>
</p:splitButton>
<h5>AutoHide (false)</h5>
<p:inputText id="autohide" value="Hover Me" />
<p:overlayPanel for="autohide" style="width:350px" showEvent="mouseover" hideEvent="mouseout" autoHide="false">
<p>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:overlayPanel>
<h5>Choose Data</h5>
<p:growl id="msgs" showDetail="true" />
<p:commandButton id="movieBtn" value="Find" type="button" icon="pi pi-search" />
<p:overlayPanel for="movieBtn" dynamic="true" style="width:600px" widgetVar="moviePicker">
<p:dataTable var="movie" value="#{movieView.movieList}" rows="5" paginator="true" selectionMode="single"
selection="#{movieView.movie}" rowKey="#{movie.movie}">
<p:ajax event="rowSelect" listener="#{movieView.onRowSelect}" update=":form:msgs" oncomplete="PF('moviePicker').hide()"/>
<p:column headerText="Movie">
<h:outputText value="#{movie.movie}"/>
</p:column>
<p:column headerText="Directed By">
<h:outputText value="#{movie.directedBy}"/>
</p:column>
<p:column headerText="Genres">
<h:outputText value="#{movie.genres}"/>
</p:column>
<p:column headerText="Run Time(min.)">
<h:outputText value="#{movie.runTime}"/>
</p:column>
</p:dataTable>
</p:overlayPanel>
<h5>Data Iteration</h5>
<p:dataTable id="basicDT" var="product" value="#{dtSelectionView.products1}">
<p:column style="width:32px;text-align: center">
<p:commandButton update=":form:productDetail" styleClass="ui-button-flat"
oncomplete="PF('productOP').show('#{component.clientId}')"
icon="pi pi-search" title="View">
<f:setPropertyActionListener value="#{product}"
target="#{dtSelectionView.selectedProduct}"/>
</p:commandButton>
</p:column>
<p:column headerText="Code">
<h:outputText value="#{product.code}"/>
</p:column>
<p:column headerText="Name">
<h:outputText value="#{product.name}"/>
</p:column>
<p:column headerText="Category">
<h:outputText value="#{product.category}"/>
</p:column>
<p:column headerText="Quantity">
<h:outputText value="#{product.quantity}"/>
</p:column>
</p:dataTable>
<p:overlayPanel widgetVar="productOP" dismissable="false" showCloseIcon="true" dynamic="true">
<p:outputPanel id="productDetail" style="text-align:center;">
<p:column rendered="#{not empty dtSelectionView.selectedProduct}">
<div class="product">
<div class="product-grid-item p-3 border-0">
<div class="product-grid-item-top">
<div>
<i class="pi pi-tag product-category-icon"/>
<span class="product-category">#{dtSelectionView.selectedProduct.category}</span>
</div>
<span class="product-badge status-#{dtSelectionView.selectedProduct.inventoryStatus.statusName}">#{dtSelectionView.selectedProduct.inventoryStatus.text}</span>
</div>
<div class="product-grid-item-content">
<p:graphicImage
name="demo/images/product/#{dtSelectionView.selectedProduct.image}"/>
<div class="product-name">#{dtSelectionView.selectedProduct.name}</div>
<div class="product-description">#{dtSelectionView.selectedProduct.description}</div>
<p:rating readonly="true" value="#{dtSelectionView.selectedProduct.rating}"/>
</div>
<div class="product-grid-item-bottom">
<h:outputText value="#{dtSelectionView.selectedProduct.price}"
styleClass="product-price">
<f:convertNumber currencySymbol="$" type="currency"/>
</h:outputText>
<p:commandButton value="Add To Cart" icon="pi pi-shopping-cart"
disabled="#{dtSelectionView.selectedProduct.inventoryStatus == 'OUTOFSTOCK'}">
</p:commandButton>
</div>
</div>
</div>
</p:column>
</p:outputPanel>
</p:overlayPanel>
</h:form>
</div>
package org.primefaces.showcase.view.overlay;
import jakarta.annotation.PostConstruct;
import jakarta.enterprise.context.RequestScoped;
import jakarta.inject.Named;
import java.util.ArrayList;
import java.util.List;
import io.quarkus.runtime.annotations.RegisterForReflection;
@Named
@RequestScoped
@RegisterForReflection(serialization = true)
public class ImageSwitchView {
private List<String> images;
@PostConstruct
public void init() {
images = new ArrayList<String>();
images.add("nature1.jpg");
images.add("nature2.jpg");
images.add("nature3.jpg");
images.add("nature4.jpg");
}
public List<String> getImages() {
return images;
}
}
package org.primefaces.showcase.view.overlay;
import jakarta.annotation.PostConstruct;
import jakarta.enterprise.context.RequestScoped;
import jakarta.faces.application.FacesMessage;
import jakarta.faces.context.FacesContext;
import jakarta.inject.Named;
import java.util.ArrayList;
import java.util.List;
import io.quarkus.runtime.annotations.RegisterForReflection;
import org.primefaces.event.SelectEvent;
import org.primefaces.showcase.domain.Movie;
@Named
@RequestScoped
@RegisterForReflection(serialization = true)
public class MovieView {
private Movie movie;
private List<Movie> movieList;
public List<Movie> getMovieList() {
return movieList;
}
@PostConstruct
public void init() {
movieList = new ArrayList<Movie>();
movieList.add(new Movie("The Lord of the Rings: The Two Towers", "Peter Jackson", "Fantasy, Epic", 179));
movieList.add(new Movie("The Amazing Spider-Man 2", "Marc Webb", "Action", 142));
movieList.add(new Movie("Iron Man 3", "Shane Black", "Action", 109));
movieList.add(new Movie("Thor: The Dark World", "Alan Taylor", "Action, Fantasy", 112));
movieList.add(new Movie("Avatar", "James Cameron", "Science Fiction", 160));
movieList.add(new Movie("The Lord of the Rings: The Fellowship of the Ring", "Peter Jackson", "Fantasy, Epic", 165));
movieList.add(new Movie("Divergent", "Neil Burger", "Action", 140));
movieList.add(new Movie("The Hobbit: The Desolation of Smaug", "Peter Jackson", "Fantasy", 161));
movieList.add(new Movie("Rio 2", "Carlos Saldanha", "Comedy", 101));
movieList.add(new Movie("Captain America: The Winter Soldier", "Joe Russo", "Action", 136));
movieList.add(new Movie("Fast Five", "Justin Lin", "Action", 132));
movieList.add(new Movie("The Lord of the Rings: The Return of the King", "Peter Jackson", "Fantasy, Epic", 200));
}
public Movie getMovie() {
return movie;
}
public void setMovie(Movie movie) {
this.movie = movie;
}
public void onRowSelect(SelectEvent<Movie> event) {
FacesMessage msg = new FacesMessage("Movie Selected", event.getObject().getMovie());
FacesContext.getCurrentInstance().addMessage(null, msg);
}
}
package org.primefaces.showcase.view.data.datatable;
import jakarta.annotation.PostConstruct;
import jakarta.faces.application.FacesMessage;
import jakarta.faces.context.FacesContext;
import jakarta.faces.view.ViewScoped;
import jakarta.inject.Inject;
import jakarta.inject.Named;
import java.io.Serializable;
import java.util.List;
import io.quarkus.runtime.annotations.RegisterForReflection;
import org.primefaces.event.SelectEvent;
import org.primefaces.event.UnselectEvent;
import org.primefaces.showcase.domain.Product;
import org.primefaces.showcase.service.ProductService;
@Named("dtSelectionView")
@ViewScoped
@RegisterForReflection(serialization = true)
public class SelectionView implements Serializable {
@Inject
ProductService service;
private List<Product> products1;
private List<Product> products2;
private List<Product> products3;
private List<Product> products4;
private List<Product> products5;
private List<Product> products6;
private Product selectedProduct;
private List<Product> selectedProducts;
@PostConstruct
public void init() {
products1 = service.getProducts(10);
products2 = service.getProducts(10);
products3 = service.getProducts(10);
products4 = service.getProducts(10);
products5 = service.getProducts(10);
products6 = service.getProducts(10);
}
public List<Product> getProducts1() {
return products1;
}
public List<Product> getProducts2() {
return products2;
}
public List<Product> getProducts3() {
return products3;
}
public List<Product> getProducts4() {
return products4;
}
public List<Product> getProducts5() {
return products5;
}
public List<Product> getProducts6() {
return products6;
}
public void setService(ProductService service) {
this.service = service;
}
public Product getSelectedProduct() {
return selectedProduct;
}
public void setSelectedProduct(Product selectedProduct) {
this.selectedProduct = selectedProduct;
}
public List<Product> getSelectedProducts() {
return selectedProducts;
}
public void setSelectedProducts(List<Product> selectedProducts) {
this.selectedProducts = selectedProducts;
}
public void onRowSelect(SelectEvent<Product> event) {
FacesMessage msg = new FacesMessage("Product Selected", String.valueOf(event.getObject().getId()));
FacesContext.getCurrentInstance().addMessage(null, msg);
}
public void onRowUnselect(UnselectEvent<Product> event) {
FacesMessage msg = new FacesMessage("Product Unselected", String.valueOf(event.getObject().getId()));
FacesContext.getCurrentInstance().addMessage(null, msg);
}
}
package org.primefaces.showcase.service;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.UUID;
import jakarta.annotation.PostConstruct;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Named;
import org.primefaces.showcase.domain.InventoryStatus;
import org.primefaces.showcase.domain.Product;
@Named
@ApplicationScoped
public class ProductService {
private List<Product> products;
@PostConstruct
public void init() {
products = new ArrayList<>();
products.add(new Product(1000, "f230fh0g3", "Bamboo Watch", "Product Description", "bamboo-watch.jpg", 65,
"Accessories", 24, InventoryStatus.INSTOCK, 5));
products.add(new Product(1001, "nvklal433", "Black Watch", "Product Description", "black-watch.jpg", 72,
"Accessories", 61, InventoryStatus.INSTOCK, 4));
products.add(new Product(1002, "zz21cz3c1", "Blue Band", "Product Description", "blue-band.jpg", 79,
"Fitness", 2, InventoryStatus.LOWSTOCK, 3));
products.add(new Product(1003, "244wgerg2", "Blue T-Shirt", "Product Description", "blue-t-shirt.jpg", 29,
"Clothing", 25, InventoryStatus.INSTOCK, 5));
products.add(new Product(1004, "h456wer53", "Bracelet", "Product Description", "bracelet.jpg", 15,
"Accessories", 73, InventoryStatus.INSTOCK, 4));
products.add(new Product(1005, "av2231fwg", "Brown Purse", "Product Description", "brown-purse.jpg", 120,
"Accessories", 0, InventoryStatus.OUTOFSTOCK, 4));
products.add(new Product(1006, "bib36pfvm", "Chakra Bracelet", "Product Description", "chakra-bracelet.jpg", 32,
"Accessories", 5, InventoryStatus.LOWSTOCK, 3));
products.add(new Product(1007, "mbvjkgip5", "Galaxy Earrings", "Product Description", "galaxy-earrings.jpg", 34,
"Accessories", 23, InventoryStatus.INSTOCK, 5));
products.add(new Product(1008, "vbb124btr", "Game Controller", "Product Description", "game-controller.jpg", 99,
"Electronics", 2, InventoryStatus.LOWSTOCK, 4));
products.add(new Product(1009, "cm230f032", "Gaming Set", "Product Description", "gaming-set.jpg", 299,
"Electronics", 63, InventoryStatus.INSTOCK, 3));
products.add(new Product(1010, "plb34234v", "Gold Phone Case", "Product Description", "gold-phone-case.jpg", 24,
"Accessories", 0, InventoryStatus.OUTOFSTOCK, 4));
products.add(new Product(1011, "4920nnc2d", "Green Earbuds", "Product Description", "green-earbuds.jpg", 89,
"Electronics", 23, InventoryStatus.INSTOCK, 4));
products.add(new Product(1012, "250vm23cc", "Green T-Shirt", "Product Description", "green-t-shirt.jpg", 49,
"Clothing", 74, InventoryStatus.INSTOCK, 5));
products.add(new Product(1013, "fldsmn31b", "Grey T-Shirt", "Product Description", "grey-t-shirt.jpg", 48,
"Clothing", 0, InventoryStatus.OUTOFSTOCK, 3));
products.add(new Product(1014, "waas1x2as", "Headphones", "Product Description", "headphones.jpg", 175,
"Electronics", 8, InventoryStatus.LOWSTOCK, 5));
products.add(new Product(1015, "vb34btbg5", "Light Green T-Shirt", "Product Description", "light-green-t-shirt.jpg", 49,
"Clothing", 34, InventoryStatus.INSTOCK, 4));
products.add(new Product(1016, "k8l6j58jl", "Lime Band", "Product Description", "lime-band.jpg", 79,
"Fitness", 12, InventoryStatus.INSTOCK, 3));
products.add(new Product(1017, "v435nn85n", "Mini Speakers", "Product Description", "mini-speakers.jpg", 85,
"Clothing", 42, InventoryStatus.INSTOCK, 4));
products.add(new Product(1018, "09zx9c0zc", "Painted Phone Case", "Product Description", "painted-phone-case.jpg", 56,
"Accessories", 41, InventoryStatus.INSTOCK, 5));
products.add(new Product(1019, "mnb5mb2m5", "Pink Band", "Product Description", "pink-band.jpg", 79,
"Fitness", 63, InventoryStatus.INSTOCK, 4));
products.add(new Product(1020, "r23fwf2w3", "Pink Purse", "Product Description", "pink-purse.jpg", 110,
"Accessories", 0, InventoryStatus.OUTOFSTOCK, 4));
products.add(new Product(1021, "pxpzczo23", "Purple Band", "Product Description", "purple-band.jpg", 79,
"Fitness", 6, InventoryStatus.LOWSTOCK, 3));
products.add(new Product(1022, "2c42cb5cb", "Purple Gemstone Necklace", "Product Description", "purple-gemstone-necklace.jpg", 45,
"Accessories", 62, InventoryStatus.INSTOCK, 4));
products.add(new Product(1023, "5k43kkk23", "Purple T-Shirt", "Product Description", "purple-t-shirt.jpg", 49,
"Clothing", 2, InventoryStatus.LOWSTOCK, 5));
products.add(new Product(1024, "lm2tny2k4", "Shoes", "Product Description", "shoes.jpg", 64,
"Clothing", 0, InventoryStatus.INSTOCK, 4));
products.add(new Product(1025, "nbm5mv45n", "Sneakers", "Product Description", "sneakers.jpg", 78,
"Clothing", 52, InventoryStatus.INSTOCK, 4));
products.add(new Product(1026, "zx23zc42c", "Teal T-Shirt", "Product Description", "teal-t-shirt.jpg", 49,
"Clothing", 3, InventoryStatus.LOWSTOCK, 3));
products.add(new Product(1027, "acvx872gc", "Yellow Earbuds", "Product Description", "yellow-earbuds.jpg", 89,
"Electronics", 35, InventoryStatus.INSTOCK, 3));
products.add(new Product(1028, "tx125ck42", "Yoga Mat", "Product Description", "yoga-mat.jpg", 20,
"Fitness", 15, InventoryStatus.INSTOCK, 5));
products.add(new Product(1029, "gwuby345v", "Yoga Set", "Product Description", "yoga-set.jpg", 20,
"Fitness", 25, InventoryStatus.INSTOCK, 8));
}
public List<Product> getProducts() {
return new ArrayList<>(products);
}
public List<Product> getProducts(int size) {
if (size > products.size()) {
Random rand = new Random();
List<Product> randomList = new ArrayList<>();
for (int i = 0; i < size; i++) {
int randomIndex = rand.nextInt(products.size());
randomList.add(products.get(randomIndex));
}
return randomList;
}
else {
return new ArrayList<>(products.subList(0, size));
}
}
public List<Product> getClonedProducts(int size) {
List<Product> results = new ArrayList<>();
List<Product> originals = getProducts(size);
for (Product original : originals) {
results.add(original.clone());
}
// make sure to have unique codes
for (Product product : results) {
product.setCode(UUID.randomUUID().toString().replace("-", "").substring(0, 8));
}
return results;
}
}
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;
}
}