Grid is a Java library which provides a two-dimensional grid structure. A grid has a set of rows and columns. Each column can have a corresponding header. The grid implementation is annotated with Jackson annotations and can be rendered to JSON and XML using a Jackson renderer. A grid can be rendered to CSV using the GridUtils
utility class.
You can use Grid with Maven:
<dependency>
<groupId>org.hisp</groupId>
<artifactId>grid</artifactId>
<version>1.0.0</version>
</dependency>
To create a grid and add a few headers and rows:
Grid grid = new ListGrid()
.setTitle( "Clients" )
.addHeader( new GridHeader( "Name", "name" ) )
.addHeader( new GridHeader( "Email", "email" ) )
.addHeader( new GridHeader( "Phone", "phone" ) );
for ( Person person : people )
{
grid.addRow()
.addValue( person.getName() )
.addValue( person.getEmail() )
.addValue( person.getPhone() );
}
Render to CSV (Writer
retrieved e.g. from HttpServletResponse
):
Writer writer = response.getWriter();
GridUtils.toCsv( grid, writer );
You can find Javadoc here.