Class HtmlTableBuilder

java.lang.Object
com.illumon.util.jettyhelper.HtmlTableBuilder

public class HtmlTableBuilder
extends Object
Class to help build HTML tables that can be displayed through a web service. An instance of this class should be created, then each row's data added, and the generateHtmlString method called to receive the generated string. HtmlTableBuilder instances are not reusable. This class is not thread-safe.
  • Constructor Details

    • HtmlTableBuilder

      public HtmlTableBuilder​(@Nullable String pageName, @Nullable String alternateRowBgColor, boolean displayDate, HtmlTableBuilder.ColumnOption... columnOptions)
      Constructor that creates a table builder with all available options
      Parameters:
      pageName - the name of the table (i.e. a page header)
      alternateRowBgColor - if not null, specifies the background color to be used for alternating table rows
      displayDate - if true, add the current date/time to the page name
      columnOptions - the columns to be displayed in the table, one ColumnOption is required per column
    • HtmlTableBuilder

      public HtmlTableBuilder​(@Nullable String pageName, boolean displayDate, HtmlTableBuilder.ColumnOption... columnOptions)
      Constructor that creates a table builder using the default alternate row background color
      Parameters:
      pageName - the name of the table (i.e. the page header)
      displayDate - if true, add the current date/time to the page name
      columnOptions - the columns to be displayed in the table, one ColumnOption is required per column
  • Method Details

    • appendRow

      public void appendRow​(String colorName, Object... values)
      Append a row to the table
      Parameters:
      colorName - the color for the row, or null if the default color should be used
      values - the values to be added to each column; if not enough values are provided, then the row will be padded with empty values. These values are passed into a StringBuilder.append(value) call, so only values which are supported by StringBuilder should be passed in to this method.
    • appendRowWithDefaults

      public void appendRowWithDefaults​(Object... values)
      Append a row to the table using the default alternating-row background color; this method has a different name to distinguish it from appendRow
      Parameters:
      values - the values to be added to each column; if not enough values are provided, then the row will be padded with empty values. These values are passed into a StringBuilder.append(value) call, so only values which are supported by StringBuilder should be passed in to this method.
    • generateHtmlString

      public String generateHtmlString()
      Complete the table
      Returns:
      the String HTML table suitable for display