Theme
arya
luna-amber
luna-blue
luna-green
luna-pink
nova-dark
nova-light
saga
vela
MorphiaLazyDataModel

PrimeFaces Extensions provides a OOTB implementation for MongoDB using Morphia, which supports basic features..

pom.xml

<dependency>
    <groupId>dev.morphia.morphia</groupId>
    <artifactId>morphia-core</artifactId>
    <version>2.2.3</version>
    <optional>true</optional>
</dependency>

Bean (defaults using ID field)

new MorphiaLazyDataModel<>(MyEntity.class, () -> datastore);

Bean (using field name of class "getUuid()" for rowKey)

new MorphiaLazyDataModel<>(MyEntity.class, () -> datastore, "uuid");

Global Filter and customization

//lets implement a global filter here for the string fields
dataModel.globalFilter((query, filterMeta) -> {
    Object val = filterMeta.getFilterValue();
    query.filter(
            Filters.or(
                    Filters.regex("brand").pattern(val + "").caseInsensitive(),
                    Filters.regex("previousOwners").pattern(val + "").caseInsensitive(),
                    Filters.regex("color.name").pattern(val + "").caseInsensitive()
            )
    );
});

//override the default match mode query for the "sold" field to allow filtering with strings
dataModel.overrideFieldQuery("sold", (query, filterMeta) -> {
    if (filterMeta.getFilterValue().toString().startsWith("y")) {
        query.filter(Filters.eq("sold", true));
    } else if (filterMeta.getFilterValue().toString().startsWith("n")) {
        query.filter(Filters.eq("sold", false));
    }
});
Components and more
PrimeFaces Extensions Showcase - © 2011-2023,PrimeFaces: 14.0.5,PrimeFaces Extensions: 14.0.5,JSF: Apache MyFaces JSF-2.3 Core Impl 2.3.10,Server: jetty/9.4.36.v20210114,Build time: 2024-09-10 21:01