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));
}
});