In the previous article, I described the creation of an HTML table report with AJAX filtering and user sorting of columns — using a few lines of code written into a single Java command. For this, I used the ReportBuilder class from the Ujorm framework. Today, I’d like to show you how to place formatted content into the cells of such a table, as well as a few more improvements. What will the final table look like?
Our filter now has a new input field for limiting the number of displayed rows. We can insert the first column into our table, containing the sort order number of the row. The star classification of a hotel can be displayed using a list of appropriate characters with a tooltip, and the final column contains a link to the hotel home page. The original behaviour of the table remains the same, the updated source code is here:
Java
Notes:
The TableBuilder class allows you to add your own configuration to in the constructor, and this will influence certain properties of the output HTML code. If that is not enough, you can try overriding one of the methods of the TableBuilder class.
Practical usage is for small projects and administration, where frontend developers are not available. Due to its small size, it can be used in embedded devices. The original inspiration for the API was the ListDataProvider class, which was added to the Ujorm project in 2014 - for the creation of tables using the Apache Wicket framework. But I liked this alternative implementation (without any dependencies) so much, that I just had to try writing my own solution for the purpose. If anyone wants to add their own code to the current solution, I recommend using the GitHub project’s issue feature.
To run the project you’ll need JDK version 8 and a web browser with support for JavaScript Vanilla ES6, but the JavaScript used here doesn’t require any further libraries. The project can be run in Windows using the run.cmd script (on Linux using the run.sh script). On first execution, the necessary libraries will be downloaded.
#java #tutorial #html #java #html