JavaServer Faces: Web App Scopes & Managed Beans

ninetimesdissemblingSoftware and s/w Development

Nov 10, 2012 (5 years and 8 months ago)


JavaServer Faces:

Web App Scopes & Managed Beans

Compiled from

“Understanding Scope and Managed Beans”

About Scopes

As long as a user stays on a page, the component
values are remembered even when the page redisplays,
such as when the user clicks a button that returns null.
(when the user leaves the page, the component values

To make values available to other pages, or to make
values available to the same page, should the user
return to it, you need to store the values.

When you create a project from the IDE, the IDE creates
managed beans

for storing values:




Managed Beans

a JavaBeans object that a JSF web application instantiates and stores in
either request scope, session scope, or application scope.

Before you create a bean property to store a value, you must determine the
appropriate scope for the property's value. (Why?)

The following figure illustrates the duration of each type of scope.

Application scope

lasts until the server stops the application. Values that you
store in an application bean are available to every session and every request that
uses the same application map.

e.g., counter to keep track of all users using the app, drop
down list of measurement
types for all to access

Session scope

begins when a user first accesses a page in the web application
and ends when the session times out due to inactivity, or when the web
application invalidates the session, such as, for example, by calling

e.g., user’s login info, shopping cart

Request scope

begins when the user submits the page and ends when the
response is fully rendered, whatever page that is.

e.g., anything that is only needed in 1 request/response cycle (timestamp in the
programming language voting sample app)

Managed Beans

Language Voting Web App

Language Voting Web App (cont’d)