=== modified file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/grid/ListGrid.java' --- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/grid/ListGrid.java 2011-02-23 21:08:31 +0000 +++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/grid/ListGrid.java 2011-02-23 21:26:24 +0000 @@ -32,7 +32,9 @@ import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; +import java.util.HashMap; import java.util.List; +import java.util.Map; import net.sf.jasperreports.engine.JRException; import net.sf.jasperreports.engine.JRField; @@ -85,6 +87,11 @@ private int currentRowReadIndex = -1; /** + * Represents a mapping between column names and the index of the column in the grid. + */ + private Map columnIndexMap = new HashMap(); + + /** * Default constructor. */ public ListGrid() @@ -132,7 +139,16 @@ return this; } - + + public Grid addHeader( GridHeader header ) + { + headers.add( header ); + + updateColumnIndexMap(); + + return this; + } + public List getHeaders() { return headers; @@ -152,14 +168,7 @@ return tempHeaders; } - - public Grid addHeader( GridHeader header ) - { - headers.add( header ); - - return this; - } - + public int getHeight() { return ( grid != null && grid.size() > 0 ) ? grid.size() : 0; @@ -288,6 +297,8 @@ row.remove( columnIndex ); } + updateColumnIndexMap(); + return this; } @@ -385,18 +396,9 @@ public Object getFieldValue( JRField field ) throws JRException { - int headerIndex = -1; - - for ( int i = 0; i < headers.size(); i++ ) - { - if ( headers.get( i ).getColumn() != null && headers.get( i ).getColumn().equals( field.getName() ) ) - { - headerIndex = i; - break; - } - } - - return headerIndex != -1 ? getRow( currentRowReadIndex ).get( headerIndex ) : null; + Integer index = columnIndexMap.get( field.getName() ); + + return index != null ? getRow( currentRowReadIndex ).get( index ) : null; } // ------------------------------------------------------------------------- @@ -428,6 +430,20 @@ } } + /** + * Updates the mapping between header columns and grid indexes. This method + * should be invoked whenever the columns are manipulated. + */ + private void updateColumnIndexMap() + { + columnIndexMap.clear(); + + for ( int i = 0; i < headers.size(); i++ ) + { + columnIndexMap.put( headers.get( i ).getColumn(), i ); + } + } + // ------------------------------------------------------------------------- // toString // ------------------------------------------------------------------------- === modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/result/GridJasperResult.java' --- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/result/GridJasperResult.java 2011-02-23 21:08:31 +0000 +++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/result/GridJasperResult.java 2011-02-23 21:26:24 +0000 @@ -89,8 +89,6 @@ grid = _grid != null ? _grid : grid; - System.out.println( "GRID IN JASPER RESULT " + grid ); - // --------------------------------------------------------------------- // Configure response // ---------------------------------------------------------------------