Versions Compared

Key

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

...

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.descdescription());
    }

 

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.

...