我正在基于 Vaadin Tutorial 中的 SimpleAddressBook 构建小型应用程序。
就像在教程中一样,我有一个扩展 BeanItemContainer 的容器,用于填充表格。
为什么我得到:
java.lang.IllegalArgumentException: Ids must exist in the Container or as a generated column , missing id: title
尽管我的 bean 类中有一个“title”字段?
豆项容器:
package com.example.library.content;
import java.io.Serializable;
import com.vaadin.data.util.BeanItemContainer;
@SuppressWarnings("serial")
public class BooksContainer extends BeanItemContainer<Book> implements
Serializable {
public static final Object[] NATURAL_COL_ORDER = new Object[] {
"title", "author", "year", "ISBN"};
public static final String[] COL_HEADERS_POLISH = new String[] {
"Tytul", "Autor", "Rok", "ISBN"};
public BooksContainer() throws InstantiationException,
IllegalAccessException {
super(Book.class);
}
public static BooksContainer createWithTestData() {
final String[] titles = { "Peter", "Alice", "Joshua", "Mike", "Olivia"};
final String[] authors = { "Smith", "Gordon", "Simpson", "Brown",
"Clavel"};
final int[] years = { 1594, 1834, 1922, 1983, 1984};
final String isbns[] = { "4215 Blandit Av.", "452-8121 Sem Ave",
"279-4475 Tellus Road", "4062 Libero. Av.", "7081 Pede. Ave",};
BooksContainer booksContainer = null;
try {
booksContainer = new BooksContainer();
for (int i = 0; i < titles.length; i++) {
Book book = new Book();
book.setTitle(titles[i]);
book.setAuthor(authors[i]);
book.setYear(years[i]);
book.setISBN(isbns[i]);
booksContainer.addItem(book);
}
} catch (InstantiationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return booksContainer;
}
}
书:
package com.example.library.content;
public class Book {
private String title;
private String author;
private int year;
private String ISBN;
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public int getYear() {
return year;
}
public String getISBN() {
return ISBN;
}
public void setYear(int year) {
this.year = year;
}
public void setISBN(String isbn) {
this.ISBN = isbn;
}
}
书籍表视图
public class BooksTableView extends Table {
public BooksTableView(LibraryApplication libraryApp) {
setSizeFull();
setContainerDataSource(BooksContainer.createWithTestData());
setVisibleColumns(BooksContainer.NATURAL_COL_ORDER);
setColumnHeaders(BooksContainer.COL_HEADERS_POLISH);
}
}