|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
T - row/item model object typepublic interface IDataSource<T>
Interface used to provide data to data views. This interface allows to create a paged DataGrid without being able to know the exact amount of rows upfront.
An example of situation when the row count can be determined:
IDataSource<User> source = new IDataSource<User>() {
public void query(IQuery query, IQueryResult<User> result) {
UserDao dao = DaoManager.getUserDao(); // code to get a DAO or service object
result.setTotalCount(dao.getUserCount());
Collection<User> users = dao.getUsers(query.getFrom(), query.getCount());
result.setItems(users.iterator());
}
public IModel<User> model(User object) {
return new DetachableUserModel(object);
}
}
An example of situation when the row count can't be determined. The pagination then only allows
to advance by one page. The idea is to retrieve n + 1 rows when n rows are requested to decide
whether the next page should be available:
IDataSource<User> source = new IDataSource<User>() {
public void query(IQuery query, IQueryResult<User> result) {
UserDao dao = DaoManager.getUserDao(); // code to get a DAO or service object
Collection<User> users = dao.getUsers(query.getFrom(), query.getCount() + 1);
if (users.size() < query.getCount() + 1) {
result.setTotalCount(IQueryResult.NO_MORE_ITEMS);
} else {
result.setTotalCount(IQueryResult.MORE_ITEMS);
}
result.setItems(users.iterator());
}
public IModel<User> model(User object) {
return new DetachableUserModel(object);
}
}
| Nested Class Summary | |
|---|---|
static interface |
IDataSource.IQuery
Specifies the subset of data to be loaded. |
static interface |
IDataSource.IQueryResult<T>
Used to pass the total row count and the loaded item to the caller of query(IDataSource.IQuery, IDataSource.IQueryResult) method. |
| Method Summary | |
|---|---|
IModel<T> |
model(T object)
Allows wrapping the object in a model which will be set as model of the appropriate row. |
void |
query(IDataSource.IQuery query,
IDataSource.IQueryResult<T> result)
Implementation of this method should load subset of the data specified by query.getFrom() and query.getCount(). |
| Methods inherited from interface org.apache.wicket.model.IDetachable |
|---|
detach |
| Method Detail |
|---|
void query(IDataSource.IQuery query,
IDataSource.IQueryResult<T> result)
query.getFrom() and query.getCount(). Also if the total item count
can be determined, it should be passed to result.
query - Specified the amount and position of items to be queriedresult - Allows to set the total item count and result itemsIModel<T> model(T object)
object -
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||