out.println("Getting value for row " + i);
return selection.get(i - this.indexFrom);
}
public Class getRowType()
{
return Celebrity.class;
}
}
First of all, when creating an instance of CelebritySource, we are passing an
implementation of IDataSource that will imitate an actual data source to its
constructor. In real life this could be some Data Access Object.
The GridDataSource interface that we implemented contains four methods:
getAvailableRows(), prepare(), getRowValue(), and getRowType(). The
simplest of them is getRowType(). It simply reports which type of objects are served
by this implementation of GridDataSource.
Chapter 5
[ 137 ]
The getAvailableRows method returns the total number of entities available in the
data source (this is needed to know the number of pages and to construct the pager
properly). In our case, we are simply returning the size of a collection. In real life, this
method could contain a request to the database that would return the total available
number of records in a search result, without actually returning all those records.
If you insert an output statement into this method, you will notice that it is invoked
by Grid several times, even while a single page of the table is displayed.
Pages:
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185