12.07.2015 Views

Beginning Java EE 6 with GlassFish 3, Second Edition

Beginning Java EE 6 with GlassFish 3, Second Edition

Beginning Java EE 6 with GlassFish 3, Second Edition

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

CHAPTER 12 ■ PROCESSING AND NAVIGATIONIn the “Putting It All Together” section of Chapter 10, we had a first page (newBook.xhtml) displayinga form to create a book. Once you click the Create button, the book is created and the managed beannavigates to the listBooks.xhtml page, which will list all the books. Once the page is loaded into thebrowser, the Create a new book link at the bottom of the page allows you to go back to the previous page(as shown in Figure 12-4).Figure 12-4. Navigating between newBook.xhtml and listBooks.xhtmlThe page flow is simple but it still needs a managed bean (BookController) to do some businesslogic and navigation. Both pages use buttons and links components for navigating and interacting <strong>with</strong>the managed bean. The newBook.xhtml page uses a button to call the doCreateBook() method of themanaged bean:The doCreateBook() method will then invoke an EJB to persist a Book entity in the database. ThelistBooks.xhtml page uses a link to just go back to the newBook.xhtml page <strong>with</strong>out doing anyprocessing:The button does not directly call the page it needs to go to. It invokes a method on the managedbean that is responsible for navigation and decides which page to load next. The navigation operates ona set of rules that define all the application’s possible navigation paths. The code of the managed bean inListing 12-8 uses the simplest form of navigation rules: each method defines the page it needs to go to.357

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!