258 Patterns: Implementing Self-Service in an SOA Environment
in the JSP page. Although technically speaking we could edit the configuration
file and change this JSP to bean mapping, there is no particular reason to that.
Therefore, following this default behavior, the design of the ITSOMart application
is such that each JSP page will have a unique corresponding backing bean.
The backing beans are declared with request scope. Because the bean’s
purpose is strictly to interact with the one JSP file in particular, there is no reason
its information needs to be stored beyond the request.
In addition to rendering data, the other key operation in a Faces JSP page is to
trigger an action. These actions cause the application to perform some operation
and might include navigating to another page. They are triggered by JSF UI
components such as command buttons and links.
From a JSF design perspective, we could declare a managed bean dedicated
explicitly to handle actions. However, this is not strictly necessary. The default
behavior of Rational Software Architect is to create an action handler method in
the standard backing bean associated with the JSP page. In that case, the
backing bean is logically also an action handling bean.
The ITSOMart front-end follows the simple approach of placing the action
handler on the backing bean. There is little need for dedicated action classes,
since the relevant operations are already clearly isolated in the
OrderSystemSessionFacade object, as seen in the object model on 9.2.3,
“Object model” on page 246.
For example, again using the create customer case, the pc_CreateCustomer
backing bean has a doCreateCustomeAction method. This method is bound as
the handler for the Create button (a JSF <hx:commandExButton> UI component)
on the CreateCustomer.jsp page.
Although backing beans get and set data on a specific page, they are not meant
to carry data across multiple screens. Therefore, if an application has persistent
data which needs to be carried through to multiple screens, a dedicated
managed bean is generally used for that purpose.
The scope of the data bean depends on the requirement of the application. The
most common scenario for e-business applications, is probably that a certain
amount of data gets carried through a user session, the shopping cart being the
classic case. In that case, the managed bean should be declared with session
scope. The declaration of the data bean is done in the faces-config.xml