Learn Java for Web Development

(Tina Meador) #1

292 CHAPTER 6: Component-Based Web Development Using JSF 2


Listing 6-20. BookController.java



  1. package com.apress.books.controller;



  2. import javax.faces.bean.ManagedBean;

  3. import javax.faces.bean.RequestScoped;

  4. import com.apress.books.model.Book;

  5. import com.apress.books.service.BookService;

  6. import java.util.List;



  7. @ManagedBean

  8. @RequestScoped

  9. public class BookController {



  10. private BookService bookService ;

  11. private List bookList;



  12. public String listAllBooks() {

  13. bookList = bookService.getAllBooks();

  14. return "bookList.xhtml";

  15. }



  16. public BookService getBookService() {

  17. return bookService;

  18. }



  19. public void setBookService(BookService bookService) {

  20. this.bookService = bookService;

  21. }



  22. public List getBookList() {

  23. return bookList;

  24. }

  25. public void setBookList(List bookList) {

  26. this.bookList = bookList;

  27. }

  28. }


   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.

Free download pdf