JSF表仍为空

时间:2017-04-25 23:19:58

标签: jsf jsf-2

我尝试使用JSF显示元素列表,但表仍为空。

这是我目前的结果:

  

#{book.author}#{book.title}

这是我的图书类:

public class Book {


private int id;
private String title;
private String author;

public Book(int id, String title, String author) {
    this.id = id;
    this.title = title;
    this.author = author;
}

public String getAuthor() {
    return author;
}

public void setAuthor(String author) {
    this.author = author;
}

public int getId() {
    return id;
}

public void setId(int id) {
    this.id = id;
}

public String getTitle() {
    return title;
}

public void setTitle(String title) {
    this.title = title;
}

}

这是我的Bean:

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;

/**
 *
 * @author Arne
 */
@ManagedBean(name = "bookCatalog")
@RequestScoped
public class BookCatalog implements Serializable {

    /**
     * Creates a new instance of BookCatalog
     */
    public BookCatalog() {
    }
    private List<Book> books;

    @PostConstruct
    public void init() {
        books = new ArrayList<>();
        books.add(new Book(0, "Die Verwandlung", "Franz Kafka"));
        books.add(new Book(1, "Der Bau", "Franz Kafka"));
        books.add(new Book(2, "Amerika", "Franz Kafka"));
    }

    public List<Book> getBooks() {

        return books;
    }

}

这是我的HTML:

 <?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
      xmlns:f="http://xmlns.jcp.org/jsf/core">
    <h:head>
        <title>Books</title>
    </h:head>
    <h:body>
        <h:dataTable value="#{bookCatalog.books}" var="book">
            <h:column>#{book.author}</h:column>
            <h:column>#{book.title}</h:column>
        </h:dataTable>   
    </h:body>
</html>

我看不出我做错了什么。 谁看到我的错误?

先谢谢

0 个答案:

没有答案