final ListView<Book> lv = new ListView<Book>("demoListView", getSomeBooks()) {
private static final long serialVersionUID = 1L;
@Override
protected void populateItem(final ListItem<Book> item) {
final Book book = item.getModelObject();
item.add(new Label("title", book.getTitle()));
item.add(new Label("isbn", book.getISBN()));
item.add(new Label("price", ObjectUtils.toString(book.getPrice())));
}
/**
* Note: Override this method and provide a model that stores the object identifier
* instead of the index in the list if you plan to perform CRUD-operations on the items
* in the list.
*/
@Override
protected IModel<Book> getListItemModel(//
final IModel<? extends List<Book>> listViewModel, final int index) {
final Book book = listViewModel.getObject().get(index);
// This model serializes the complete book object
//return Model.of(book);
// OR
// This model serializes the identifier of the book object,
// and searches the book in the list through its identifier.
return new IdentifyingListItemModel<Book, UUID>(this, book.getId());
}
};
add(lv);
}