Comment puis-je afficher une liste d'éléments d'un Bean sur une page Web JSF?

Je suis nouveau sur JSF et dans le processus d'apprentissage im la construction d'une librairie en ligne de l'application.

J'ai 1 classe et 1 fève: Book.java et BookCatelogBean.java. Le Livre de classe a 3 propriétés: idtitleet author avec ses getters et setters. Le BookCatelogBean contient un ArrayList<Book> où je remplir avec Books (dans le futur, je vais le connecter à une base de données).

J'ai deux pages: index.xhtml et book.xhtml. Je veux afficher la liste des titres des livres sur index.xhtml chaque formaté comme un RESTE de lien et de leur carte d'identité à book.xhtmlcomme suit: <h:link outcome="book?id=#{bookCatelogBean.id}" value="#{bookCatelogBean.title}" />

Je sais comment les utiliser BookCatelogBean pour afficher 1 book mais je veux afficher tous? J'ai une idée pour appeler une méthode de BookCatelogBean appelé getAllBooks() qui renvoie chacun des livres titres, mais comment aurais-je de retour de chacun d'eux à l'index.xhtml est un JavaserverFace lien à la place d'une chaîne de caractères?

Grâce

Voici mon code:

Book.java

package bookshop;

import java.io.Serializable;

public class Book implements Serializable {

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

    public Book(int id, String title, String author){
        this.title = title;
        this.id = id;
        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;
    }
}

BookCatelogBean.java

package bookshop;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

@ManagedBean
@SessionScoped
public class BookCatelogBean implements Serializable {
    private int currentItem = 0;

    private ArrayList<Book> books = new ArrayList<Book>(Arrays.asList(
            new Book(1, "Theory of Money and Credit", "Ludwig von Mises"),
            new Book(2, "Man, Economy and State", "Murry Rothbard"),
            new Book(3, "Real Time Relationships", "Stefan Molyneux")));

    public String getTitle(){
        return books.get(currentItem).getTitle();
    }

    public int getId(){
        return books.get(currentItem).getId();
    }

    public String getAuthor(){
        return books.get(currentItem).getAuthor();
    }

}

index.xhtml

<?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://java.sun.com/jsf/html">
    <h:head>
        <title>BookShop</title>

    </h:head>
    <h:body>
        <h:link outcome="book?id=#{bookCatelogBean.id}" value="#{bookCatelogBean.title}" />
    </h:body>
</html>

source d'informationauteur Jonathan