Products

  1. webMethods CAF 7.1.1
  2. BPM Designer 7.0
  3. BPM Designer 7.1
  4. MWS 7.0
  5. MWS 7.1

Article Types

  1. Sample Applications
  2. Core Concepts
  3. External References
  4. Webinars

Key Subjects

  1. Web Services
  2. Database
  3. JavaScript
  4. JSF Controls
  5. Task Development
  6. Task Inbox
  7. Task Assignments
  8. Task Events
  9. Debugging
  10. Web Application
 
MOST POPULAR
  1. CAF JavaDocs
  2. Designer Online Help
  3. CAF Java(Script)Docs
  4. Confirmation Dialog Tutorial
  5. CAF Samples for webMethods 7.1...
  6. CAF and JSF
  7. JSF Binding Expressions
  8. Dynamic Panel Switch Applicati...
WHATS NEW
  1. Session State Mgmt
  2. Print Table
  3. Popup Dialog

Session State Mgmt

This article describes some simple techniques for getting and setting session data.
  1. webMethods CAF 7.1.1
  2. | Web Application
  3. | Sample Applications
Managing Session State Between Views in a Web Application


This use case illustrates session handling in a CAF Web-based application. It demonstrates how to manage session attributes among the views of a Web application.
The use case demonstrates session handling using a shopping cart application, which allows users to add books to a shopping cart. The Web application manages the shopping cart as a session (scope) attribute among the pages of the application; that is, the shopping cart is a managed bean in session scope.
*
Start adding Java classes, managed bean properties, and content providers that your application will require, but that do not manipulate the shared session information. (The detailed step-by-step instructions will illustrate how to work with the shared session information.)
For the sample that illustrates this use case, the following are the items that are added to the Default view in preparation for the steps described in this article.
Defines information about an individual book. Each row of the tables that are in the views contain a Book object.
Defines different categories of books, for example, children’s books or biographies.
A page bean property in the Default view to hold the categories defined by the BooksCategory class.
The Default view will contain a Dropdown control that is bound to the Books Category property; as a result, the Dropdown control will list the categories. The user selects a category to limit the books the application displays in a table on the Default view.
Books By Category content provider
A content provider in the Default view that is based on the Books By Category property. The application uses it to populate a table in the Default view.
Note: The items for the Billing Page require information shared with the Default view, which is the focus of this article. As a result, the step-by-step instructions will describe how to add these items.
For the sample that illustrates this use case, the following are the items that are added to the Default view in preparation for the steps described in this article.
*
Dropdown list that contains categories that a user can select to limit the display of books in the table. This control is bound to the Books Category property.
*
Raise On Change control that causes the application to execute the Async Hidden Command control after the user changes the Dropdown list.
Note: The items for the Billing Page require information shared with the Default view, which is the focus of this article. As a result, the step-by-step instructions will describe how to add these items.
This article describes how to work with session attributes by first working with the main view of an application (in the case of the sample, the Default view), and then referencing the attributes in the other views of the application.
For the sample that illustrates the use case, you will add a BooksCart class that maintains information about the books a user adds to the shopping cart. The BooksCart class has methods to manipulate the contents of the shopping cart, for example:
*
Add a managed bean to hold the data you want to share across views in the application. At this point, you only add this to one of the views.
For the sample, you will add a BooksCart managed bean to the Default view. To the BooksCart managed bean, add a BooksInCart property that holds information about the books in the shopping cart.
The action handler for the button adds a book to the shopping cart. As a result, when a user clicks the button, the selected book in the table is added to the shopping cart; the application updates the BooksInCart property of the BooksCart managed bean, which is used to maintain the list of books in the shopping cart.
*
To use the same managed bean in other views of the application, from the main view of the application add a reference of the shared managed bean to other views.
For the sample, from the Default view you add a reference of the BooksCart managed bean to the Billing Page view. As a result, the BooksCart managed bean is available in the Billing Page view, as well as the BooksInCart property that was added to the BooksCart managed bean.
*
Command button labeled “Remove From Cart”. The action handler for this button removes a book from the shopping cart. As a result, when a user clicks the button, the selected book in the shopping cart is removed.
a
In Designer: File > New > Other.
b
On the Select a Wizard page, choose Java > Class and click Next.
For the package name, type com.webmethods.caf.
Type BooksCart.
d
In the Project Explorer view, open the BooksCart.java file (project_name/Java Resources: src/com.webmethods.caf/BooksCart.java).
For the sample, add the BooksCart managed bean to the Default view, which the application will use to maintain the list of books in the shopping cart:
a
From the Bindings view, right-click Managed Beans > default (the view's managed bean), and select New > Managed Bean.
Type BooksCart.
Select session.
d
Click Finish.