Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Overview

A number of Java classes are provided to help support the tabular views in the GUI.

Table views in the ONOS Web UI are supported by java code running on the server. See the Creating a Tabular View tutorial for details on implementing a table view.

When the Table Builder Service is used to create the client-side code for a table view, "data request" events will be sent to the server automatically:

  • when the table view is first loaded
  • every 2 seconds, if auto-refresh is enabled
  • every time a column header is clicked (for a new sort order)

The typical structure of a table request handler on the server side can be seen in the tutorial

This page will focus on how to customize the default behavior. 

Default Behavior

By default, a TableModel instance is created for you, which uses a default Formatter and default Comparator for each table column.

When a request is made for table data, a list of items is retrieved from the business layer; each item corresponding to a single row in the table. The columns of the table represent attributes of the item. Populating the table model involves iterating over the list of items to add new TableModel.Row instances for each one. The cell(String columnId, Object value) method is used to associate an object with a particular column for that row. Typical code might look like this:

Code Block
languagejava
linenumberstrue
    @Override
    protected void populateTable(TableModel tm, ObjectNode payload) {
        FooService fs = get(FooService.class);
        for (Foo foo : fs.getFoos()) {
            populateRow(tm.addRow(), foo);
        }
    }
 
    private void populateRow(TableModel.Row row, Foo foo) {
        row.cell(ID, foo.id())
                .cell(BAR, foo.bar())
                .cell(BAZ, foo.baz())
                .cell(DESC, foo.desc());
    }

 

Once the table model has been constructed and populated, the table rows are sorted (based on selected column and sort direction), and then the model is converted into a JSON representation to be shipped back to the client for displaying in the table view.

DefaultCellComparator

The default cell comparator compares objects in a column by looking to see if the objects implement the Comparable<T> interface:

  • if they do, delegate to the compareTo() method
  • if they do not, convert the objects to strings and compare those

This has the advantage of using the natural sort order of objects, where the comparable behavior has been implemented, by default.

DefaultCellFormatter

The default cell formatter simply invokes the toString() method on each object, to generate the string representation to be displayed in the table cell.

 

Customizing the Behavior

 

 

 

 

 

 

...