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 NAVIGATIONLife Cycle and Callback AnnotationsThe previous chapter explained the life cycle of a page (<strong>with</strong> six phases from receiving the request torendering the response). Managed beans also have a life cycle (see Figure 12-3), which is completelydifferent from that of the page. In fact, managed beans have a similar life cycle to stateless session beans;if they do exist, it is for the lifetime of the defined scope.Figure 12-3. The managed bean life cycleManaged beans running in a servlet container can use the @PostConstruct and @PreDestroyannotations. After the container creates an instance of a managed bean, it calls the @PostConstructcallback method, if any. After this stage, the managed bean is bound to a scope and responds to anyuser’s request. Before removing the managed bean, the container calls the @PreDestroy method. Thesemethods can be used to initialize attributes, or to create and release any external resource.NavigationWeb applications are made of multiple pages that you need to navigate through. Depending on theapplication, you can have various levels of navigation <strong>with</strong> page flows that are more or lesssophisticated. You can think of wizards, where you can go back to the previous or initial page, businesscases where you go to a particular page depending on a certain rule, and so on. JSF has multiple optionsfor navigation and allows you to control the flow, based on single pages or globally for the entireapplication.When you just want to go from page to page by clicking a link or a button <strong>with</strong>out doing anyprocessing, you can use the UI components , and :But most of the time this is not enough because you need to access a business tier or a database toretrieve or process data. In this case, you would use and <strong>with</strong> theiraction attribute that allows you to target managed bean methods, as opposed to targeting a page <strong>with</strong> or :356

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

Saved successfully!

Ooh no, something went wrong!