<h:form>
<div class="card">
<h5>DataTable: paging, sorting, filtering and row expansion</h5>
<p:dataTable var="customer" value="#{loadingView.customers}" paginator="true" rows="5"
paginatorTemplate="{FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}">
<p:ajax event="rowToggle" listener="#{loadingView.slow}"/>
<p:column style="width:2rem" ariaHeaderText="Row Toggler">
<p:rowToggler/>
</p:column>
<p:column headerText="Name" sortBy="#{customer.name}" filterBy="#{customer.name}">
<h:outputText value="#{customer.name}"/>
</p:column>
<p:column headerText="Country" sortBy="#{customer.country}" filterBy="#{customer.country}">
<h:outputText value="#{customer.country.name}"/>
</p:column>
<p:column headerText="Company" sortBy="#{customer.company}" filterBy="#{customer.company}">
<h:outputText value="#{customer.company}"/>
</p:column>
<p:rowExpansion>
<div class="p-3">
#{customer.name} works at #{customer.company} (#{customer.country.name}), represented
by #{customer.representative.name}.
</div>
</p:rowExpansion>
</p:dataTable>
</div>
<div class="grid">
<div class="col-12 md:col-6">
<div class="card">
<h5>DataTable: live scroll</h5>
<p:dataTable var="customer" value="#{loadingView.liveScrollCustomers}" scrollable="true"
scrollHeight="250" liveScroll="true" scrollRows="20">
<p:column headerText="Name">
<h:outputText value="#{customer.name}"/>
</p:column>
<p:column headerText="Company">
<h:outputText value="#{customer.company}"/>
</p:column>
</p:dataTable>
</div>
</div>
<div class="col-12 md:col-6">
<div class="card">
<h5>DataTable: virtual scroll</h5>
<p:dataTable var="customer" value="#{loadingView.virtualScrollCustomers}" scrollable="true"
scrollHeight="250" virtualScroll="true" scrollRows="20" rows="40">
<p:column headerText="Name">
<h:outputText value="#{customer.name}"/>
</p:column>
<p:column headerText="Company">
<h:outputText value="#{customer.company}"/>
</p:column>
</p:dataTable>
</div>
</div>
</div>
<div class="grid">
<div class="col-12 md:col-6">
<div class="card">
<h5>TreeTable: expand a node</h5>
<p:treeTable value="#{loadingView.treeTable}" var="document">
<p:ajax event="expand" listener="#{loadingView.slow}"/>
<p:column headerText="Name">
<h:outputText value="#{document.name}"/>
</p:column>
<p:column headerText="Type">
<h:outputText value="#{document.type}"/>
</p:column>
</p:treeTable>
</div>
</div>
<div class="col-12 md:col-6">
<div class="card">
<h5>Tree: expand a node (dynamic)</h5>
<p:tree value="#{loadingView.tree}" var="document" dynamic="true">
<p:ajax event="expand" listener="#{loadingView.slow}"/>
<p:treeNode expandedIcon="pi pi-folder-open" collapsedIcon="pi pi-folder">
<h:outputText value="#{document.name}"/>
</p:treeNode>
<p:treeNode type="app" icon="pi pi-save">
<h:outputText value="#{document.name}"/>
</p:treeNode>
<p:treeNode type="document" icon="pi pi-file">
<h:outputText value="#{document.name}"/>
</p:treeNode>
<p:treeNode type="excel" icon="pi pi-file-excel">
<h:outputText value="#{document.name}"/>
</p:treeNode>
<p:treeNode type="travel" icon="pi pi-file-pdf">
<h:outputText value="#{document.name}"/>
</p:treeNode>
<p:treeNode type="picture" icon="pi pi-image">
<h:outputText value="#{document.name}"/>
</p:treeNode>
<p:treeNode type="video" icon="pi pi-video">
<h:outputText value="#{document.name}"/>
</p:treeNode>
</p:tree>
</div>
</div>
</div>
<div class="grid">
<div class="col-12 md:col-6">
<div class="card">
<h5>TabView: open a tab (dynamic)</h5>
<p:tabView dynamic="true" cache="false">
<p:ajax event="tabChange" listener="#{loadingView.slow}"/>
<p:tab title="Overview">
<p class="m-0">The content of a tab is loaded each time it is opened.</p>
</p:tab>
<p:tab title="Details">
<p class="m-0">Loaded on demand: the active bar of the tab runs meanwhile.</p>
</p:tab>
<p:tab title="History">
<p class="m-0">The current tab stays active until the new content is shown.</p>
</p:tab>
</p:tabView>
</div>
</div>
<div class="col-12 md:col-6">
<div class="card">
<h5>AccordionPanel: open a tab (dynamic)</h5>
<p:accordionPanel dynamic="true" cache="false" activeIndex="-1">
<p:ajax event="tabChange" listener="#{loadingView.slow}"/>
<p:tab title="Overview">
<p class="m-0">The content of a tab is loaded each time it is opened.</p>
</p:tab>
<p:tab title="Details">
<p class="m-0">Loaded on demand: the toggler becomes a spinner meanwhile.</p>
</p:tab>
</p:accordionPanel>
</div>
</div>
</div>
<div class="grid">
<div class="col-12 md:col-6">
<div class="card">
<h5>Fieldset: expand (dynamic)</h5>
<p:fieldset legend="Details" toggleable="true" collapsed="true" dynamic="true">
<p class="m-0">#{loadingView.fieldsetContent}</p>
</p:fieldset>
</div>
</div>
<div class="col-12 md:col-6">
<div class="card">
<h5>SelectOneMenu: open (dynamic)</h5>
<p:selectOneMenu dynamic="true" style="width: 15rem">
<f:selectItem itemLabel="Select a country" itemValue=""/>
<f:selectItems value="#{loadingView.countryNames}"/>
</p:selectOneMenu>
</div>
</div>
</div>
<div class="grid">
<div class="col-12 md:col-6">
<div class="card">
<h5>CommandButton</h5>
<p:commandButton value="Save" icon="pi pi-check" action="#{loadingView.slow}"
process="@this" styleClass="mr-2"/>
<p:commandButton value="Delete" action="#{loadingView.slow}" process="@this"
styleClass="p-button-danger p-button-outlined"/>
</div>
</div>
<div class="col-12 md:col-6">
<div class="card">
<h5>AutoComplete</h5>
<p:autoComplete completeMethod="#{loadingView.completeCountry}" placeholder="Search a country"
scrollHeight="250"/>
</div>
</div>
</div>
</h:form>
package org.primefaces.showcase.view.misc;
import org.primefaces.model.LazyDataModel;
import org.primefaces.model.TreeNode;
import org.primefaces.showcase.domain.Country;
import org.primefaces.showcase.domain.Customer;
import org.primefaces.showcase.domain.Document;
import org.primefaces.showcase.service.CountryService;
import org.primefaces.showcase.service.CustomerService;
import org.primefaces.showcase.service.DocumentService;
import org.primefaces.showcase.view.data.datatable.LazyCustomerDataModel;
import java.io.Serializable;
import java.util.List;
import java.util.concurrent.TimeUnit;
import jakarta.annotation.PostConstruct;
import jakarta.faces.context.FacesContext;
import jakarta.faces.view.ViewScoped;
import jakarta.inject.Inject;
import jakarta.inject.Named;
@Named
@ViewScoped
public class LoadingView implements Serializable {
@Inject
private CustomerService customerService;
@Inject
private DocumentService documentService;
@Inject
private CountryService countryService;
private LazyDataModel<Customer> customers;
private LazyDataModel<Customer> liveScrollCustomers;
private LazyDataModel<Customer> virtualScrollCustomers;
private TreeNode<Document> tree;
private TreeNode<Document> treeTable;
@PostConstruct
public void init() {
// LazyCustomerDataModel waits 1.5s in load() like a slow datasource
customers = new LazyCustomerDataModel(customerService.getCustomers(200));
liveScrollCustomers = new LazyCustomerDataModel(customerService.getCustomers(200));
virtualScrollCustomers = new LazyCustomerDataModel(customerService.getCustomers(200));
tree = documentService.createDocuments();
treeTable = documentService.createDocuments();
}
/**
* Listener of the expand / rowToggle / tabChange events: simulates a slow server, so the loading state is visible.
*/
public void slow() {
sleep(1500);
}
/** The options of the dynamic SelectOneMenu, slow when its panel is loaded. */
public List<String> getCountryNames() {
slowOnce("_dynamicload");
return countryService.getCountries().stream().map(Country::getName).toList();
}
/** The content of the dynamic Fieldset, slow when it is loaded. */
public String getFieldsetContent() {
slowOnce("_contentLoad");
return "Loaded on the first expand: the toggler becomes a spinner meanwhile.";
}
/**
* Simulates a slow server once per request, when the request loads dynamic content (a parameter ending with the
* given suffix): getters are called more than once.
*/
private static void slowOnce(String suffix) {
FacesContext context = FacesContext.getCurrentInstance();
boolean loading = context.getExternalContext().getRequestParameterMap().keySet().stream()
.anyMatch(name -> name.endsWith(suffix));
if (loading && context.getAttributes().putIfAbsent(LoadingView.class.getName() + suffix, true) == null) {
sleep(1500);
}
}
public List<String> completeCountry(String query) {
sleep(1000);
String lowerCaseQuery = query.toLowerCase();
return countryService.getCountries().stream()
.map(Country::getName)
.filter(name -> name.toLowerCase().contains(lowerCaseQuery))
.limit(10)
.toList();
}
private static void sleep(long millis) {
try {
TimeUnit.MILLISECONDS.sleep(millis);
}
catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
public LazyDataModel<Customer> getCustomers() {
return customers;
}
public LazyDataModel<Customer> getLiveScrollCustomers() {
return liveScrollCustomers;
}
public LazyDataModel<Customer> getVirtualScrollCustomers() {
return virtualScrollCustomers;
}
public TreeNode<Document> getTree() {
return tree;
}
public TreeNode<Document> getTreeTable() {
return treeTable;
}
}
package org.primefaces.showcase.service;
import org.primefaces.showcase.domain.Country;
import org.primefaces.showcase.domain.Customer;
import org.primefaces.showcase.domain.CustomerStatus;
import org.primefaces.showcase.domain.Representative;
import org.primefaces.util.Constants;
import java.security.SecureRandom;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;
import jakarta.annotation.PostConstruct;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Named;
@Named
@ApplicationScoped
public class CustomerService {
private Random random = new SecureRandom();
private Country[] countries;
private Representative[] representatives;
private String[] firstNames;
private String[] lastNames;
private String[] companies;
@PostConstruct
public void init() {
countries = new Country[]{
new Country(0, "Argentina", "ar"),
new Country(1, "Australia", "au"),
new Country(2, "Brazil", "br"),
new Country(3, "Canada", "ca"),
new Country(4, "Germany", "de"),
new Country(5, "France", "fr"),
new Country(6, "India", "in"),
new Country(7, "Italy", "it"),
new Country(8, "Japan", "jp"),
new Country(9, "Russia", "ru"),
new Country(10, "Spain", "es"),
new Country(11, "United Kingdom", "gb")};
companies = new String[]{"Benton, John B Jr", "Chanay, Jeffrey A Esq", "Chemel, James L Cpa", "Feltz Printing Service",
"Printing Dimensions", "Chapman, Ross E Esq", "Morlong Associates", "Commercial Press", "Truhlar And Truhlar Attys",
"King, Christopher A Esq", "Dorl, James J Esq", "Rangoni Of Florence", "Feiner Bros", "Buckley Miller Wright",
"Rousseaux, Michael Esq"};
representatives = new Representative[]{
new Representative("Amy Elsner", "amyelsner.png"),
new Representative("Anna Fali", "annafali.png"),
new Representative("Asiya Javayant", "asiyajavayant.png"),
new Representative("Bernardo Dominic", "bernardodominic.png"),
new Representative("Elwin Sharvill", "elwinsharvill.png"),
new Representative("Ioni Bowcher", "ionibowcher.png"),
new Representative("Ivan Magalhaes", "ivanmagalhaes.png"),
new Representative("Onyama Limba", "onyamalimba.png"),
new Representative("Stephen Shaw", "stephenshaw.png"),
new Representative("Xuxue Feng", "xuxuefeng.png")};
firstNames = new String[]{"James", "David", "Jeanfrancois", "Ivar", "Tony",
"Adams", "Claire", "Costa", "Juan", "Maria", "Jennifer",
"Stacey", "Leja", "Morrow", "Arvin", "Darci", "Izzy",
"Ricardo", "Clifford", "Emily", "Kadeem", "Mujtaba", "Aika",
"Mayumi", "Misaki", "Silvio", "Nicolas", "Antonio",
"Deepesh", "Aditya", "Aruna", "Jones", "Julie", "Smith",
"Johnson", "Francesco", "Salvatore", "Kaitlin", "Faith",
"Maisha", "Jefferson", "Leon", "Rodrigues", "Alejandro",
"Munro", "Cody", "Chavez", "Sinclair", "Isabel", "Octavia",
"Murillo", "Greenwood", "Wickens", "Ashley"};
lastNames = new String[]{"Butt", "Darakjy", "Venere", "Paprocki", "Foller",
"Morasca", "Tollner", "Dilliard", "Wieser", "Marrier", "Amigon",
"Maclead", "Caldarera", "Ruta", "Albares", "Poquette", "Garufi",
"Gaucho", "Rim", "Whobrey", "Flosi", "Nicka", "Inouye",
"Kolmetz", "Royster", "Slusarski", "Iturbide", "Caudy",
"Chui", "Kusko", "Figeroa", "Vocelka", "Stenseth", "Glick",
"Sergi", "Shinko", "Stockham", "Ostrosky", "Gillian",
"Rulapaugh", "Schemmer", "Oldroyd", "Campain", "Perin",
"Ferencz", "Saylors", "Briddick", "Waycott", "Bowley", "Malet",
"Malet", "Bolognia", "Nestle", "Doe"};
}
public List<Customer> getCustomers(int number) {
List<Customer> customers = new ArrayList<>();
for (int i = 0; i < number; i++) {
customers.add(
new Customer(i + 1000, getName(), getCompany(), getCountry(), getDate(),
CustomerStatus.random(), getActivity(), getRepresentative()));
}
return customers;
}
public List<Country> getCountries() {
return Arrays.asList(countries);
}
public CustomerStatus[] getCustomerStatus() {
return CustomerStatus.values();
}
public List<Representative> getRepresentatives() {
return Arrays.asList(representatives);
}
private String getName() {
return firstNames[random.nextInt(firstNames.length)] + Constants.SPACE
+ (char) (random.nextInt(26) + 'A') + Constants.SPACE
+ lastNames[random.nextInt(lastNames.length)];
}
private Country getCountry() {
return countries[random.nextInt(countries.length)];
}
private String getCompany() {
return companies[random.nextInt(companies.length)];
}
private LocalDate getDate() {
LocalDate now = LocalDate.now();
long randomDay = ThreadLocalRandom.current().nextLong(now.minusDays(30).toEpochDay(), now.toEpochDay());
return LocalDate.ofEpochDay(randomDay);
}
private int getActivity() {
return random.nextInt(100);
}
private Representative getRepresentative() {
return representatives[random.nextInt(representatives.length)];
}
}
package org.primefaces.showcase.service;
import org.primefaces.model.CheckboxTreeNode;
import org.primefaces.model.DefaultTreeNode;
import org.primefaces.model.TreeNode;
import org.primefaces.showcase.domain.Document;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Named;
@Named
@ApplicationScoped
public class DocumentService {
public TreeNode<Document> createDocuments() {
TreeNode<Document> root = new DefaultTreeNode<>(new Document("Files", "-", "Folder"), null);
TreeNode<Document> applications = new DefaultTreeNode<>(new Document("Applications", "100kb", "Folder"), root);
TreeNode<Document> cloud = new DefaultTreeNode<>(new Document("Cloud", "20kb", "Folder"), root);
TreeNode<Document> desktop = new DefaultTreeNode<>(new Document("Desktop", "150kb", "Folder"), root);
TreeNode<Document> documents = new DefaultTreeNode<>(new Document("Documents", "75kb", "Folder"), root);
TreeNode<Document> downloads = new DefaultTreeNode<>(new Document("Downloads", "25kb", "Folder"), root);
TreeNode<Document> main = new DefaultTreeNode<>(new Document("Main", "50kb", "Folder"), root);
TreeNode<Document> other = new DefaultTreeNode<>(new Document("Other", "5kb", "Folder"), root);
TreeNode<Document> pictures = new DefaultTreeNode<>(new Document("Pictures", "150kb", "Folder"), root);
TreeNode<Document> videos = new DefaultTreeNode<>(new Document("Videos", "1500kb", "Folder"), root);
//Applications
TreeNode<Document> primeface = new DefaultTreeNode<>(new Document("Primefaces", "25kb", "Folder"), applications);
TreeNode<Document> primefacesapp = new DefaultTreeNode<>("app", new Document("primefaces.app", "10kb", "Application"), primeface);
TreeNode<Document> nativeapp = new DefaultTreeNode<>("app", new Document("native.app", "10kb", "Application"), primeface);
TreeNode<Document> mobileapp = new DefaultTreeNode<>("app", new Document("mobile.app", "5kb", "Application"), primeface);
TreeNode<Document> editorapp = new DefaultTreeNode<>("app", new Document("editor.app", "25kb", "Application"), applications);
TreeNode<Document> settingsapp = new DefaultTreeNode<>("app", new Document("settings.app", "50kb", "Application"), applications);
//Cloud
TreeNode<Document> backup1 = new DefaultTreeNode<>("document", new Document("backup-1.zip", "10kb", "Zip"), cloud);
TreeNode<Document> backup2 = new DefaultTreeNode<>("document", new Document("backup-2.zip", "10kb", "Zip"), cloud);
//Desktop
TreeNode<Document> note1 = new DefaultTreeNode<>("document", new Document("note-meeting.txt", "50kb", "Text"), desktop);
TreeNode<Document> note2 = new DefaultTreeNode<>("document", new Document("note-todo.txt", "100kb", "Text"), desktop);
//Documents
TreeNode<Document> work = new DefaultTreeNode<>(new Document("Work", "55kb", "Folder"), documents);
TreeNode<Document> expenses = new DefaultTreeNode<>("document", new Document("Expenses.doc", "30kb", "Document"), work);
TreeNode<Document> resume = new DefaultTreeNode<>("document", new Document("Resume.doc", "25kb", "Resume"), work);
TreeNode<Document> home = new DefaultTreeNode<>(new Document("Home", "20kb", "Folder"), documents);
TreeNode<Document> invoices = new DefaultTreeNode<>("excel", new Document("Invoice.xsl", "20kb", "Excel"), home);
//Downloads
TreeNode<Document> spanish = new DefaultTreeNode<>(new Document("Spanish", "10kb", "Folder"), downloads);
TreeNode<Document> tutorial1 = new DefaultTreeNode<>("document", new Document("tutorial-a1.txt", "5kb", "Text"), spanish);
TreeNode<Document> tutorial2 = new DefaultTreeNode<>("document", new Document("tutorial-a2.txt", "5kb", "Text"), spanish);
TreeNode<Document> travel = new DefaultTreeNode<>(new Document("Travel", "15kb", "Folder"), downloads);
TreeNode<Document> hotelpdf = new DefaultTreeNode<>("travel", new Document("Hotel.pdf", "10kb", "PDF"), travel);
TreeNode<Document> flightpdf = new DefaultTreeNode<>("travel", new Document("Flight.pdf", "5kb", "PDF"), travel);
//Main
TreeNode<Document> bin = new DefaultTreeNode<>("document", new Document("bin", "50kb", "Link"), main);
TreeNode<Document> etc = new DefaultTreeNode<>("document", new Document("etc", "100kb", "Link"), main);
TreeNode<Document> var = new DefaultTreeNode<>("document", new Document("var", "100kb", "Link"), main);
//Other
TreeNode<Document> todotxt = new DefaultTreeNode<>("document", new Document("todo.txt", "3kb", "Text"), other);
TreeNode<Document> logopng = new DefaultTreeNode<>("picture", new Document("logo.png", "2kb", "Picture"), other);
//Pictures
TreeNode<Document> barcelona = new DefaultTreeNode<>("picture", new Document("barcelona.jpg", "90kb", "Picture"), pictures);
TreeNode<Document> primeng = new DefaultTreeNode<>("picture", new Document("primefaces.png", "30kb", "Picture"), pictures);
TreeNode<Document> prime = new DefaultTreeNode<>("picture", new Document("prime.jpg", "30kb", "Picture"), pictures);
//Videos
TreeNode<Document> primefacesmkv = new DefaultTreeNode<>("video", new Document("primefaces.mkv", "1000kb", "Video"), videos);
TreeNode<Document> introavi = new DefaultTreeNode<>("video", new Document("intro.avi", "500kb", "Video"), videos);
return root;
}
public TreeNode<Document> createCheckboxDocuments() {
TreeNode<Document> root = new CheckboxTreeNode<>(new Document("Files", "-", "Folder"), null);
TreeNode<Document> applications = new CheckboxTreeNode<>(new Document("Applications", "100kb", "Folder"), root);
TreeNode<Document> cloud = new CheckboxTreeNode<>(new Document("Cloud", "20kb", "Folder"), root);
TreeNode<Document> desktop = new CheckboxTreeNode<>(new Document("Desktop", "150kb", "Folder"), root);
TreeNode<Document> documents = new CheckboxTreeNode<>(new Document("Documents", "75kb", "Folder"), root);
TreeNode<Document> downloads = new CheckboxTreeNode<>(new Document("Downloads", "25kb", "Folder"), root);
TreeNode<Document> main = new CheckboxTreeNode<>(new Document("Main", "50kb", "Folder"), root);
TreeNode<Document> other = new CheckboxTreeNode<>(new Document("Other", "5kb", "Folder"), root);
TreeNode<Document> pictures = new CheckboxTreeNode<>(new Document("Pictures", "150kb", "Folder"), root);
TreeNode<Document> videos = new CheckboxTreeNode<>(new Document("Videos", "1500kb", "Folder"), root);
//Applications
TreeNode<Document> primeface = new CheckboxTreeNode<>(new Document("Primefaces", "25kb", "Folder"), applications);
TreeNode<Document> primefacesapp = new CheckboxTreeNode<>("app", new Document("primefaces.app", "10kb", "Application"), primeface);
TreeNode<Document> nativeapp = new CheckboxTreeNode<>("app", new Document("native.app", "10kb", "Application"), primeface);
TreeNode<Document> mobileapp = new CheckboxTreeNode<>("app", new Document("mobile.app", "5kb", "Application"), primeface);
TreeNode<Document> editorapp = new CheckboxTreeNode<>("app", new Document("editor.app", "25kb", "Application"), applications);
TreeNode<Document> settingsapp = new CheckboxTreeNode<>("app", new Document("settings.app", "50kb", "Application"), applications);
//Cloud
TreeNode<Document> backup1 = new CheckboxTreeNode<>("document", new Document("backup-1.zip", "10kb", "Zip"), cloud);
TreeNode<Document> backup2 = new CheckboxTreeNode<>("document", new Document("backup-2.zip", "10kb", "Zip"), cloud);
//Desktop
TreeNode<Document> note1 = new CheckboxTreeNode<>("document", new Document("note-meeting.txt", "50kb", "Text"), desktop);
TreeNode<Document> note2 = new CheckboxTreeNode<>("document", new Document("note-todo.txt", "100kb", "Text"), desktop);
//Documents
TreeNode<Document> work = new CheckboxTreeNode<>(new Document("Work", "55kb", "Folder"), documents);
TreeNode<Document> expenses = new CheckboxTreeNode<>("document", new Document("Expenses.doc", "30kb", "Document"), work);
TreeNode<Document> resume = new CheckboxTreeNode<>("document", new Document("Resume.doc", "25kb", "Resume"), work);
TreeNode<Document> home = new CheckboxTreeNode<>(new Document("Home", "20kb", "Folder"), documents);
TreeNode<Document> invoices = new CheckboxTreeNode<>("excel", new Document("Invoice.xsl", "20kb", "Excel"), home);
//Downloads
TreeNode<Document> spanish = new CheckboxTreeNode<>(new Document("Spanish", "10kb", "Folder"), downloads);
TreeNode<Document> tutorial1 = new CheckboxTreeNode<>("document", new Document("tutorial-a1.txt", "5kb", "Text"), spanish);
TreeNode<Document> tutorial2 = new CheckboxTreeNode<>("document", new Document("tutorial-a2.txt", "5kb", "Text"), spanish);
TreeNode<Document> travel = new CheckboxTreeNode<>(new Document("Travel", "15kb", "Folder"), downloads);
TreeNode<Document> hotelpdf = new CheckboxTreeNode<>("travel", new Document("Hotel.pdf", "10kb", "PDF"), travel);
TreeNode<Document> flightpdf = new CheckboxTreeNode<>("travel", new Document("Flight.pdf", "5kb", "PDF"), travel);
//Main
TreeNode<Document> bin = new CheckboxTreeNode<>("document", new Document("bin", "50kb", "Link"), main);
TreeNode<Document> etc = new CheckboxTreeNode<>("document", new Document("etc", "100kb", "Link"), main);
TreeNode<Document> var = new CheckboxTreeNode<>("document", new Document("var", "100kb", "Link"), main);
//Other
TreeNode<Document> todotxt = new CheckboxTreeNode<>("document", new Document("todo.txt", "3kb", "Text"), other);
TreeNode<Document> logopng = new CheckboxTreeNode<>("picture", new Document("logo.png", "2kb", "Picture"), other);
//Pictures
TreeNode<Document> barcelona = new CheckboxTreeNode<>("picture", new Document("barcelona.jpg", "90kb", "Picture"), pictures);
TreeNode<Document> primeng = new CheckboxTreeNode<>("picture", new Document("primefaces.png", "30kb", "Picture"), pictures);
TreeNode<Document> prime = new CheckboxTreeNode<>("picture", new Document("prime.jpg", "30kb", "Picture"), pictures);
//Videos
TreeNode<Document> primefacesmkv = new CheckboxTreeNode<>("video", new Document("primefaces.mkv", "1000kb", "Video"), videos);
TreeNode<Document> introavi = new CheckboxTreeNode<>("video", new Document("intro.avi", "500kb", "Video"), videos);
return root;
}
}
package org.primefaces.showcase.service;
import org.primefaces.showcase.domain.Country;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import jakarta.annotation.PostConstruct;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Named;
@Named
@ApplicationScoped
public class CountryService {
private List<Country> countries;
private Map<Integer, Country> countriesAsMap;
private List<Country> locales;
private Map<Integer, Country> localesAsMap;
public static Stream<Country> toCountryStream(String... isoCodes) {
return Stream.of(isoCodes)
.map(isoCode -> new Locale.Builder().setRegion(isoCode).build())
.map(CountryService::toCountry);
}
private static Locale toLocale(String language, String country) {
return new Locale.Builder().setLanguage(language).setRegion(country).build();
}
public static Country toCountry(Locale locale) {
return CountryService.toCountry(locale, false);
}
public static Country toCountry(Locale locale, boolean rtl) {
//use hash code from locale to have a reproducible ID (required for CountryConverter)
return new Country(locale.hashCode(), locale, rtl);
}
@PostConstruct
public void init() {
countries = CountryService.toCountryStream(Locale.getISOCountries())
.sorted(Comparator.comparing(Country::getName))
.collect(Collectors.toList());
locales = new ArrayList<>();
locales.add(CountryService.toCountry(Locale.US));
locales.add(CountryService.toCountry(Locale.UK));
locales.add(CountryService.toCountry(toLocale("en", "AU")));
locales.add(CountryService.toCountry(Locale.FRANCE));
locales.add(CountryService.toCountry(Locale.GERMANY));
locales.add(CountryService.toCountry(toLocale("de", "AT")));
locales.add(CountryService.toCountry(toLocale("de", "CH")));
locales.add(CountryService.toCountry(Locale.ITALY));
locales.add(CountryService.toCountry(Locale.KOREA));
locales.add(CountryService.toCountry(toLocale("es", "ES")));
locales.add(CountryService.toCountry(toLocale("ca", "ES")));
locales.add(CountryService.toCountry(toLocale("nl", "NL")));
locales.add(CountryService.toCountry(toLocale("pt", "BR")));
locales.add(CountryService.toCountry(toLocale("pt", "PT")));
locales.add(CountryService.toCountry(toLocale("ar", "SA"), true));
locales.add(CountryService.toCountry(toLocale("ar", "TN"), true));
locales.add(CountryService.toCountry(toLocale("bg", "BG")));
locales.add(CountryService.toCountry(toLocale("bn", "BD")));
locales.add(CountryService.toCountry(toLocale("bs", "BA")));
locales.add(CountryService.toCountry(toLocale("cs", "CZ")));
locales.add(CountryService.toCountry(toLocale("el", "GR")));
locales.add(CountryService.toCountry(toLocale("et", "EE")));
locales.add(CountryService.toCountry(toLocale("fa", "IR"), true));
locales.add(CountryService.toCountry(toLocale("fi", "FI")));
locales.add(CountryService.toCountry(toLocale("da", "DK")));
locales.add(CountryService.toCountry(toLocale("hi", "IN")));
locales.add(CountryService.toCountry(toLocale("in", "ID")));
locales.add(CountryService.toCountry(toLocale("is", "IS")));
locales.add(CountryService.toCountry(toLocale("hr", "HR")));
locales.add(CountryService.toCountry(toLocale("ja", "JP")));
locales.add(CountryService.toCountry(toLocale("hu", "HU")));
locales.add(CountryService.toCountry(toLocale("he", "IL"), true));
locales.add(CountryService.toCountry(toLocale("ka", "GE")));
locales.add(CountryService.toCountry(toLocale("ckb", "IQ"), true));
locales.add(CountryService.toCountry(toLocale("km", "KH")));
locales.add(CountryService.toCountry(toLocale("ky", "KG")));
locales.add(CountryService.toCountry(toLocale("kk", "KZ")));
locales.add(CountryService.toCountry(toLocale("lt", "LT")));
locales.add(CountryService.toCountry(toLocale("lv", "LV")));
locales.add(CountryService.toCountry(toLocale("ms", "MY")));
locales.add(CountryService.toCountry(toLocale("no", "NO")));
locales.add(CountryService.toCountry(toLocale("pl", "PL")));
locales.add(CountryService.toCountry(toLocale("ro", "RO")));
locales.add(CountryService.toCountry(toLocale("ru", "RU")));
locales.add(CountryService.toCountry(toLocale("sk", "SK")));
locales.add(CountryService.toCountry(toLocale("sl", "SI")));
locales.add(CountryService.toCountry(toLocale("sr", "BA")));
locales.add(CountryService.toCountry(toLocale("sr", "RS")));
locales.add(CountryService.toCountry(toLocale("sv", "SE")));
locales.add(CountryService.toCountry(toLocale("th", "TH")));
locales.add(CountryService.toCountry(toLocale("tr", "TR")));
locales.add(CountryService.toCountry(toLocale("uk", "UA")));
locales.add(CountryService.toCountry(toLocale("uz", "UZ")));
locales.add(CountryService.toCountry(toLocale("vi", "VN")));
locales.add(CountryService.toCountry(Locale.SIMPLIFIED_CHINESE));
locales.add(CountryService.toCountry(Locale.TRADITIONAL_CHINESE));
}
public List<Country> getCountries() {
return new ArrayList<>(countries);
}
public Map<Integer, Country> getCountriesAsMap() {
if (countriesAsMap == null) {
countriesAsMap = getCountries().stream().collect(Collectors.toMap(Country::getId, country -> country));
}
return countriesAsMap;
}
public List<Country> getLocales() {
return new ArrayList<>(locales);
}
public Map<Integer, Country> getLocalesAsMap() {
if (localesAsMap == null) {
localesAsMap = getLocales().stream().collect(Collectors.toMap(Country::getId, country -> country));
}
return localesAsMap;
}
}
package org.primefaces.showcase.domain;
import java.io.Serializable;
import java.util.Locale;
import java.util.Objects;
public class Country implements Serializable, Comparable<Country> {
private int id;
private String name;
private String code;
private Locale locale;
private boolean rtl;
public Country() {
}
public Country(int id, Locale locale) {
this(id, locale.getDisplayCountry(), locale.getCountry().toLowerCase(), locale);
}
public Country(int id, Locale locale, boolean rtl) {
this(id, locale.getDisplayCountry(), locale.getCountry().toLowerCase(), locale);
this.rtl = rtl;
}
public Country(int id, String name, String code) {
this(id, name, code, null);
}
public Country(int id, String name, String code, Locale locale) {
this.id = id;
this.name = name;
this.code = code;
this.locale = locale;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public Locale getLocale() {
return locale;
}
public void setLocale(Locale locale) {
this.locale = locale;
}
public String getLanguage() {
return locale == null ? "en" : locale.getLanguage();
}
public String getDisplayLanguage() {
return locale == null ? "English" : locale.getDisplayLanguage();
}
public boolean isRtl() {
return rtl;
}
public void setRtl(boolean rtl) {
this.rtl = rtl;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Country country = (Country) o;
return id == country.id
&& Objects.equals(name, country.name)
&& Objects.equals(code, country.code);
}
@Override
public int hashCode() {
return Objects.hash(id, name, code);
}
@Override
public String toString() {
return name;
}
@Override
public int compareTo(Country o) {
return name.compareTo(o.name);
}
}
package org.primefaces.showcase.domain;
import java.io.Serial;
import java.io.Serializable;
import java.time.LocalDate;
import java.util.Objects;
public class Customer implements Serializable {
@Serial private static final long serialVersionUID = 1L;
private int id;
private String name;
private String company;
private Country country;
private LocalDate date;
private CustomerStatus status;
private int activity;
private Representative representative;
public Customer() {
}
public Customer(int id, String name, String company, Country country, LocalDate date, CustomerStatus status, int activity,
Representative representative) {
this.id = id;
this.name = name;
this.company = company;
this.country = country;
this.date = date;
this.status = status;
this.activity = activity;
this.representative = representative;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getCompany() {
return company;
}
public void setCompany(String company) {
this.company = company;
}
public Country getCountry() {
return country;
}
public void setCountry(Country country) {
this.country = country;
}
public LocalDate getDate() {
return date;
}
public void setDate(LocalDate date) {
this.date = date;
}
public CustomerStatus getStatus() {
return status;
}
public void setStatus(CustomerStatus status) {
this.status = status;
}
public int getActivity() {
return activity;
}
public void setActivity(int activity) {
this.activity = activity;
}
public Representative getRepresentative() {
return representative;
}
public void setRepresentative(Representative representative) {
this.representative = representative;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Customer customer = (Customer) o;
return id == customer.id
&& activity == customer.activity
&& Objects.equals(name, customer.name)
&& Objects.equals(company, customer.company)
&& Objects.equals(country, customer.country)
&& Objects.equals(date, customer.date)
&& status == customer.status
&& Objects.equals(representative, customer.representative);
}
@Override
public int hashCode() {
return Objects.hash(id, name, company, country, date, status, activity, representative);
}
}
package org.primefaces.showcase.domain;
import java.util.Random;
public enum CustomerStatus {
QUALIFIED,
UNQUALIFIED,
NEGOTIATION,
NEW,
RENEWAL,
PROPOSAL;
public static CustomerStatus random() {
Random random = new Random();
return values()[random.nextInt(values().length)];
}
}
package org.primefaces.showcase.domain;
import java.io.Serial;
import java.io.Serializable;
import java.util.Objects;
public class Representative implements Serializable, Comparable<Representative> {
@Serial private static final long serialVersionUID = 1L;
private String name;
private String image;
public Representative() {
}
public Representative(String name, String image) {
this.name = name;
this.image = image;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getImage() {
return image;
}
public void setImage(String image) {
this.image = image;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Representative that = (Representative) o;
return Objects.equals(name, that.name)
&& Objects.equals(image, that.image);
}
@Override
public int hashCode() {
return Objects.hash(name, image);
}
@Override
public String toString() {
return name;
}
@Override
public int compareTo(Representative o) {
return name.compareTo(o.name);
}
}
package org.primefaces.showcase.domain;
import java.io.Serializable;
public class Document implements Serializable, Comparable<Document> {
private String name;
private String size;
private String type;
public Document(String name, String size, String type) {
this.name = name;
this.size = size;
this.type = type;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSize() {
return size;
}
public void setSize(String size) {
this.size = size;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
//Eclipse Generated hashCode and equals
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + ((size == null) ? 0 : size.hashCode());
result = prime * result + ((type == null) ? 0 : type.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;
}
Document other = (Document) obj;
if (name == null) {
if (other.name != null) {
return false;
}
}
else if (!name.equals(other.name)) {
return false;
}
if (size == null) {
if (other.size != null) {
return false;
}
}
else if (!size.equals(other.size)) {
return false;
}
if (type == null) {
if (other.type != null) {
return false;
}
}
else if (!type.equals(other.type)) {
return false;
}
return true;
}
@Override
public String toString() {
return name;
}
public int compareTo(Document document) {
return this.getName().compareTo(document.getName());
}
}