E. Rowlands
E. Rowlands

Reputation: 343

What GWT widget should I use to display String attributes from an Object?

In my GWT application my onSuccess(Object result) method ultimately retreives an Object with an ArrayList attribute.

This attribute contains Objects which has String attributes.

I'd like to display those String attributes to my GUI, and after researching CellTable and other widgets, I can't find a simple way to do so. I can't seem modify this CellTable source code example to fit my needs.

What would be the simplest way for me to achieve this? (Simple in the context of a novice).

Edit* Each String attribute would need to be displayed in a titled column and there will be more than one row of information.

Upvotes: 1

Views: 172

Answers (2)

Colin Alworth
Colin Alworth

Reputation: 18331

Another option is CellList<T> - this lets you take a List<T> of some kind and provide a cell that can draw each item. Since it isnt building a widget for every single item, it is much lighter weight, especially if you end up drawing hundreds or thousands of items.

In contrast to CellTable<T> or DataTable<T>, the CellList<T> maps each cell to each item, instead of assuming that each item in the list is an object with many properties, each of which should go in its own column.

As a sample of how you might draw each string, com.google.gwt.cell.client.TextCell knows just enough to take each string and automatically draw it as-is, no custom styles or anything. As you need more styling later, you can build your own cell.

Small example with comments, taken from GWT's CellListExample with comments (and edited slightly):

// Create a cell to render each value.
TextCell textCell = new TextCell();

// Create a CellList that uses the cell.
CellList<String> cellList = new CellList<String>(textCell);

// Set the total row count. This isn't strictly necessary, but it affects
// paging calculations, so its good habit to keep the row count up to date.
cellList.setRowCount(data.getListOfStrings().size(), true);

// Push the data into the widget.
cellList.setRowData(0, data.getListOfStrings());

// Add the cell list to its parent widget
parent.add(cellList);

Upvotes: 2

Knarf
Knarf

Reputation: 2156

FlexTable http://www.gwtproject.org/javadoc/latest/com/google/gwt/user/client/ui/FlexTable.html ?

or Grid http://www.gwtproject.org/javadoc/latest/com/google/gwt/user/client/ui/Grid.html ?

These are essentially the same. But Grid is faster, but needs to know its number of columns and rows before hand.

Upvotes: 1

Related Questions