GWT GXT get all the values from a selected row?

3.7k views Asked by At

I am using GXt GWt and am trying to get the values from a selected row in a tree grid, but can't seem to get it working..

E.g. if the user clicks row, i want to be able to get the values for all the columns in that row.

cm = new ColumnModel(createColumnConfig());

// Create grids based on data (held in stores), and attach listeners for when a row is clicked 
final TreeGrid<Build> nightlyResultsGrid = createTreeGrid(nightlyResultsStore);

nightlyResultsGrid.addListener(Events.RowClick, new Listener<BaseEvent>()
{
    public void handleEvent(BaseEvent clickEvent)
    {
        GridEvent gridEvent = (GridEvent)clickEvent;

        gridEvent.getModel().get("Platform").toString();
        gridEvent.getModel().get("Date").toString();
        gridEvent.getModel().get("Build").toString();
    }
}

The code above keeps generating an exception..

15:58:09.861 [ERROR] [dashboard] Uncaught exception escaped java.lang.NullPointerException: null at com.rory.mep.ui.metrics.client.UserInterface$3.handleEvent(UserInterface.java:109) at com.extjs.gxt.ui.client.event.BaseObservable.callListener(BaseObservable.java:178) at com.extjs.gxt.ui.client.event.BaseObservable.fireEvent(BaseObservable.java:86) at com.extjs.gxt.ui.client.widget.Component.fireEvent(Component.java:456) at com.extjs.gxt.ui.client.widget.grid.Grid.onClick(Grid.java:811) at com.extjs.gxt.ui.client.widget.treegrid.TreeGrid.onClick(TreeGrid.java:745)

Any help is much appreciated.

1

There are 1 answers

0
Colin Alworth On

Be sure to read the Javadocs for events when you use them. From Grid's docs:

RowClick : GridEvent(grid, rowIndex, cellIndex, event)

Fires after a row is clicked.

  • grid : this
  • rowIndex : the row index
  • cellIndex : cell index
  • index : the cell index
  • event : the dom event

The model isn't available, so getModel() is returning null. Instead, use the rowIndex with the store to get the model.