Java Reference
In-Depth Information
Now that you know what you want, let's see how you can implement it.
Implementing the solution
The next example shows a possible implementation of the ActionBazaar ordering work-
flow using a bean named DefaultOrderProcessor . As you can see, De-
faultOrderProcessor roughly models a workflow. You've ordered the methods so
that you can easily visualize how the component might be invoked from a set of JSF pages,
each implementing a stage of the ordering process. The setBidder and setItem meth-
ods are invoked by the presentation tier at the very beginning of the workflow, presumably
when the user clicks the Order button. The bidder is likely the currently logged-in user, and
the item is likely the current item selected to be ordered. In the setBidder method, the
component retrieves the shipping and billing histories of the bidder and stores them away
behind the scenes along with the bidder. In the setItem method, the shipping and billing
choices are filtered down to what's applicable to the current item. The current item is also
stored away into an instance variable for use farther down the workflow.
The next thing the JSF layer does is to prompt the user to enter the shipping details for
the order. As an ease-of-use feature, the presentation tier will allow the user to reuse any
applicable shipping details entered in the recent past. The shipping history is retrieved by
invoking the getShippingChoices method. When the user selects a shipping history
entry or enters new shipping information, it's passed back to the order processor by invok-
ing the setShipping method. When the shipping details are set, the bidder's shipping
history is also updated if needed. The order processor also immediately calculates the ship-
ping cost and updates the shipping details internally. The JSF layer can get and display the
updated shipping details by invoking the getShipping method. Similar to the shipping
details, the JSF layer can get the billing history using the getBillingChoices method
and set the billing details using the setBilling method.
The placeOrder method is invoked at the very end of the workflow, likely when the user
has reviewed the order details and clicked the Confirm Order button. The placeOrder
method actually creates and populates the Order object and attempts to bill the bidder
for the total cost of the order, including the cost of the item, shipping, insurance, and so
on. The customer can be billed in a number of ways—perhaps by charging a credit card or
crediting against a bank account. But the user is supposed to be charged; after attempting
to bill the user, the bean notifies both the bidder and seller of the results of the billing at-
tempt. If billing is successful, the seller ships to the address specified in the order. If the
Search WWH ::

Custom Search