292 CHAPTER 6: Component-Based Web Development Using JSF 2
Listing 6-20. BookController.java
- package com.apress.books.controller;
- import javax.faces.bean.ManagedBean;
- import javax.faces.bean.RequestScoped;
- import com.apress.books.model.Book;
- import com.apress.books.service.BookService;
- import java.util.List;
- @ManagedBean
- @RequestScoped
- public class BookController {
- private BookService bookService ;
- private List
bookList;
- public String listAllBooks() {
- bookList = bookService.getAllBooks();
- return "bookList.xhtml";
- }
- public BookService getBookService() {
- return bookService;
- }
- public void setBookService(BookService bookService) {
- this.bookService = bookService;
- }
- public List
getBookList() { - return bookList;
- }
- public void setBookList(List
bookList) { - this.bookList = bookList;
- }
- }
Line 17: Invokes the getAllBooks() method on bookService
Line 18: Returns the booklist.xhtml file that is composed with the template and
list.xhtml, which displays the list of books see later in Figure 6-20
Listing 6-21 illustrates the configuration metadata that is provided to the Spring IoC container. This
file is the same as created in Chapter 5 with a slight modification to configure the managed bean
BookController with the BookService.