Package com.illumon.util.jettyhelper
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.
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
HtmlTableBuilder.ColumnOption
Options for columns in the table. -
Constructor Summary
Constructors Constructor Description HtmlTableBuilder(String pageName, boolean displayDate, HtmlTableBuilder.ColumnOption... columnOptions)
Constructor that creates a table builder using the default alternate row background colorHtmlTableBuilder(String pageName, String alternateRowBgColor, boolean displayDate, HtmlTableBuilder.ColumnOption... columnOptions)
Constructor that creates a table builder with all available options -
Method Summary
Modifier and Type Method Description void
appendRow(String colorName, Object... values)
Append a row to the tablevoid
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 appendRowString
generateHtmlString()
Complete the table
-
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 rowsdisplayDate
- if true, add the current date/time to the page namecolumnOptions
- 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 namecolumnOptions
- the columns to be displayed in the table, one ColumnOption is required per column
-
-
Method Details
-
appendRow
Append a row to the table- Parameters:
colorName
- the color for the row, or null if the default color should be usedvalues
- 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
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
Complete the table- Returns:
- the String HTML table suitable for display
-