0

I try to display a list of elements with JSF but the table remains empty.

this is my current result:

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

Here is my Book class:

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;
}

}

Here is my 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;
    }

}

and this is my 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>

I cannot see what I am doing wrong. Anybody out there who sees my mistake?

Thanks in Advance

Jasper de Vries
  • 19,370
  • 6
  • 64
  • 102
smartwepa
  • 311
  • 1
  • 3
  • 11
  • do a view-source of the page, what do you see? – Kukeltje Apr 26 '17 at 05:09
  • And what is the JSF version you are actually running? – Kukeltje Apr 26 '17 at 05:16
  • @Kukeltje By view-source, do you mean looking at html in browsers developer console? If yes, yes the html remains equalt to the above posted. How can I actually figure out the JSF version? I used to Netbeans 8.2 to create the project and the jsf page. I deploy all on glassfish 4.1.1. My lack of knowledge might indicate that the problem has something to do with the JSF version. – smartwepa Apr 26 '17 at 06:46
  • Probably "Make sure that URL matches FacesServlet mapping" from the top answer in the duplicate – Jasper de Vries Apr 26 '17 at 08:31
  • I actually had a problem with the url pattern in servlet mapping. Now it works. Thanks for your help. – smartwepa Apr 26 '17 at 13:49
  • So either mark it as a duplicate yourself to (if you can) or remove the question at all... – Kukeltje Apr 27 '17 at 14:33

0 Answers0