2
我正在構建基於Vaadin教程的SimpleAddressBook的小型應用程序。Vaadin:「容器中必須存在ID」,在調用setVisibleColumns()
就像在教程中,我有一個容器擴展BeanItemContainer,它用於填充表。
爲什麼我越來越:
java.lang.IllegalArgumentException: Ids must exist in the Container or as a generated column , missing id: title
儘管事實上,我在我的Bean類「標題」字段?
BeanItemContainer:
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;
}
}
BooksTableView
public class BooksTableView extends Table {
public BooksTableView(LibraryApplication libraryApp) {
setSizeFull();
setContainerDataSource(BooksContainer.createWithTestData());
setVisibleColumns(BooksContainer.NATURAL_COL_ORDER);
setColumnHeaders(BooksContainer.COL_HEADERS_POLISH);
}
}
有時熱部署無法正常工作。嘗試停止/取消部署應用程序,從頭構建並重新啓動/重新部署應用程序。它應該工作。 – zip 2012-08-27 08:38:15
我遇到了同樣令人沮喪的問題,您是否設法解決這個問題? – Fabii 2012-11-30 03:55:13