GithubHelp home page GithubHelp logo

jobosk / extendedlazydatamodel Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 14 KB

Implementation of the LazyDataModel of Primefaces that offers pagination, sorting and filter for the contents of the table.

Java 100.00%

extendedlazydatamodel's Introduction

Objective:

Extend the LazyDataModel by Primefaces in order to implement sorting, pagination and filtering for the entity contained.

Explanation:

With the 'JPAMetaModelEntityProcessor' we automatically generate the JPA metamodel of the application classes, which we will need afterwards for type safety when interpreting the table filters, in order to build the criteria for the JPA repository request. Primefaces will automatically load the extended table model and execute the overriden load method, triggering the process that builds the JPA specification for the request, the sorting of the filters applied, and the pagination specified.

Dependencies:

Back-end:

<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.1-api</artifactId>
<version>1.0.0.Final</version>
</dependency>

<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>${springdata.version}</version>
</dependency>

Front-end:

<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>6.0</version>
</dependency>

Custom:

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.0</version>
</dependency>

Plugins (back-end):

<plugin>
<groupId>org.bsc.maven</groupId>
<artifactId>maven-processor-plugin</artifactId>
<version>2.0.5</version>
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<version>1.2.0.Final</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>process</id>
<goals>
<goal>process</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<outputDirectory>target/metamodel</outputDirectory>
<processors>
<processor>org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor</processor>
</processors>
</configuration>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>target/metamodel</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>

Usage:

In the JSF managed bean (FooBean):

private LazyDataModel<Foo> model = new ExtendedLazyDataModel<Foo>(fooRepository);

In the table layout (foo.xhtml):

<p:dataTable ... value="#{fooBean.model}" paginator="true" lazy="true" ... >
...
<p:column filterBy="#{foo.attribute}" filterMatchMode="contains" sortBy="#{foo.attribute}">
...
</p:column>
...
</p:dataTable>

extendedlazydatamodel's People

Contributors

jobosk avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.