DZone
Today I’d like to show you a simple table HTML report created with only thirteen lines of source code, written in a single command line using the Java programming language. Let’s pretend the data provision service already exists. If we wanted to offer our users some simple (sequential) content filtering for a table with column sorting, our implementation will have to add a few extra lines of code. To optimize this filtering, we’ll need to dig deeper into the backend. The web component takes its data from an object of type Stream, and so the maximum volume of presented data is limited only by the capabilities of our web browser. For my data source I used a freely available list of hotels in CSV format and it shouldn’t matter that some of the information it contains isn’t up to date. Let’s take a look at the body of the doGet()
method of our trusty old Java servlet for those thirteen lines of code we mentioned. We’ll assemble the model of our table using the ReportBuilder class from the Ujorm framework.
<div class="codeMirror-code–wrapper" data-code="new ReportBuilder("Simple Hotel Report")
.add(hotel -> hotel.getName(), "Hotel", NAME).sortable(true)
.add(hotel -> hotel.getCity().getName(), "City", CITY).sortable()
.add(hotel -> hotel.getStreet(), "Street").sortable()
.add(hotel -> hotel.getPrice(), "Price").sortable()
.add(hotel -> hotel.getCurrency(), "Currency")
.add(hotel -> hotel.getPhone(), "Phone")
.add(hotel -> hotel.getStars(), "Stars").sortable()
.setFooter(e -> e.addText("Data source: ").addLinkedText(HOTELBASE, HOTELBASE))
.build(input, output, builder -> selectHotels(builder,
DEFAULT_ROW_LIMIT,
NAME.of(input),
CITY.of(input)));” data-lang=”text/x-java”>
xxxxxxxxxx
new ReportBuilder<Hotel>("Simple Hotel Report")
.add(hotel -> hotel.getName(), "Hotel", NAME).sortable(true)
.add(hotel -> hotel.getCity().getName(), "City", CITY).sortable()
.add(hotel -> hotel.getStreet(), "Street").sortable()
.add(hotel -> hotel.getPrice(), "Price").sortable()
.add(hotel -> hotel.getCurrency(), "Currency")
.add(hotel -> hotel.getPhone(), "Phone")
.add(hotel -> hotel.getStars(), "Stars").sortable()
.setFooter(e -> e.addText("Data source: ").addLinkedText(HOTELBASE, HOTELBASE))
.build(input, output, builder -> selectHotels(builder,
DEFAULT_ROW_LIMIT,
NAME.of(input),
CITY.of(input)));