Java Reference
In-Depth Information
and is used to determine what to ask the user next. Stateful session beans make maintaining
a server-side application state as easy as possible.
That's all we're going to say about stateless session beans and the bid service for now. Let's
now turn our attention to the stateful order processor. A little later, we'll take a look at how
the bid service is actually used by JSF, as well as what the DAO code looks like.
2.2.2. Using stateful beans
Unlike stateless session beans, stateful session beans guarantee that a client can expect to
set the internal state of a bean and count on the state being maintained between any num-
ber of method calls. The container makes sure this happens by doing two important things
behind the scenes: maintaining the session and implementing the solution.
Maintaining the session
First, the container ensures that a client can reach a bean dedicated to it across more than
one method invocation. Think of this as a phone switchboard that makes sure it routes you
to the same customer service agent if you call a technical support line more than once in a
given time period (the time period is the session).
Second, the container ensures that bean instance variable values are maintained for the dur-
ation of a session without your having to write any session maintenance code. In the cus-
tomer service example, the container makes sure that your account information and call
history in a given time period automatically appear on your agent's screen when you call
technical support. The ActionBazaar ordering process is a great example for stateful ses-
sion beans because it's broken up into four workflow-like steps, each of which roughly cor-
responds to a screen presented to the user:
1 . Picking the item to the order—The user starts the ordering process by clicking the
Order Item button on the page displaying an item won, and the item is automatically
added to the order.
2 . Specifying shipping information, including the shipping method, shipping address,
insurance, and so on—The user can have one or more previous shipping details saved
in the history, including a default one. The user can view and use the saved history
to enter shipping information. The available history is filtered to only show options
appropriate for the current item (for example, an item/seller can support only a lim-
Search WWH ::




Custom Search