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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

CHAPTER 12 ■ PROCESSING AND NAVIGATIONListing 12-5. A Renamed Managed Bean@ManagedBean(name = "myManagedBean")public class BookController {private Book book = new Book();public String doCreateBook() {createBook(book);return "listBooks.xhtml";}}// Constructors, getters, settersTo invoke attributes or methods of this managed bean in your pages, you must use the overriddenname as follows:Create a new bookScopesObjects that are created as part of a managed bean have a certain lifetime and may or may not beaccessible to UI components or objects in the web application. The lifetime and accessibility of an objectis known as scope. In your web application (managed beans and pages), you can specify the scope of anobject using six different durations:• Application: This is the least restrictive duration (use the @ApplicationScopedannotation in your managed bean), <strong>with</strong> the longest life span. Objects that arecreated are available in all request/response cycles for all clients using the webapplication, for as long as the application is active. These objects can be calledconcurrently and need to be thread-safe (using the synchronized keyword).Objects <strong>with</strong> this scope can use other objects <strong>with</strong> no scope or application scope.• Session: Objects are available for any request/response cycles that belong to theclient’s session (@SessionScoped). These objects have their state persisted betweenrequests and last until the session is invalidated. Objects <strong>with</strong> this scope can useother objects <strong>with</strong> no scope, session scope, or application scope.353

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

Saved successfully!

Ooh no, something went wrong!