Home arrow Graphic Design arrow Page 6 - WebLogic Workshop Application Development Basics

WebLogic Workshop Application Development Basics

This chapter from BEA WebLogic Workshop 8.1 (Kick Start series, from Sams Publishers, by Albert J. Saganich, Jr., et al., 2004. ISBN: 0-672-32622-1) explores the WebLogic Workshop programming model and introduces enterprise application development.

Author Info:
By: Albert J. Saganich, Jr.
Rating: 4 stars4 stars4 stars4 stars4 stars / 38
June 22, 2004
  1. · WebLogic Workshop Application Development Basics
  2. · Page Flow Fundamentals
  3. · Portals
  4. · Creating Applications and Projects
  5. · Workshop Applications Breakdown
  6. · Accessing and Exposing Data via Controls
  7. · Creating Simple Rowset Controls

print this article

WebLogic Workshop Application Development Basics - Accessing and Exposing Data via Controls
(Page 6 of 7 )

Applications, whether they are designed to support Web services or be accessed as Web or portal applications, require data as content and for decision logic. In Workshop applications, logic and data are provided by controls, which are the heart of any WebLogic Workshop application. Figure 2 introduced the Workshop controls model; Figure 11 shows a deeper view. Remember, workshop supports two different types of controls: resource or extensible controls (based on J2EE resources), resources, and custom controls written by developers. Custom controls are normally used to encapsulate data access or add business logic. To the developer, controls look much like standard Java objects; however, in addition to traditional methods, controls provide a number of other capabilities, such as

  • Asynchronous method invocation—The ability to call a long-running method and return immediately while the method continues in the background. (This is shown as a slashed arrow pointing into the control in Figure 11.)


Figure 11 - A deeper look at controls.

  • Callback method—The ability to invoke a method back to the calling client from a control. (This is shown as a slashed arrow pointing out of the control in Figure 11.)

  • Conversations—The ability to call methods that start, continue, and end a conversation.

  • Transaction support—Control methods are an implicit part of a transaction without any developer work.

One area that's becoming more important in messaging is connectivity. Three specific types of connected behavior can occur in today's networks: fully connected, in which the client and server are connected all the time; disconnected, in which the client is never connected to a server; and partially connected, in which the client is sometimes connected to the server and sometimes not. The control's runtime engine has support specifically targeted toward connectivity, namely the capability to manage a conversation. Controls can clearly define what methods start, continue, and end a conversation. More important, controls provide mechanisms for obtaining conversation IDs so that applications can disconnect and then later reestablish a conversation. The ability to reestablish a conversation is key to supporting a partially connected network model. Conversations, asynchronous methods, and callbacks are covered in detail in Chapters 7, "Using the NetUI Tag Library Toolbox to Develop Sophisticated JSPs," 9, "Working with Web Services," and 11, "Working with Workflows."

Adding Controls to Page Flows

The two most common uses of controls are to gather data for display and to make a logic decision. To use a control, you must add it to a Page Flow, open an action, and call methods on the control. Figure 12 shows two methods of adding a control to a Page Flow. If the control is part of the same application, it can be added by dragging the associated .jcx (Java extensible control) or .jcs (Java custom control) file into the right side of a Page Flow's Action View. Otherwise, you can right-click in the right side of a Page Flow Action View, select Controls, and then add the control. In either case, Workshop then prompts for the variable name of the new control and adds the control to your application. Listing 3 shows the code annotations added to a Controller when a control is added. Controls can then be accessed in actions like regular Java classes.


Figure 12 - Adding a control to a Page Flow.

Listing 3 Annotations Marking a Variable As a Control

public class Controller extends PageFlowController
  * @common:control
  private controls.Weather weather;

  * @common:control
  private db.games gamesDBCtrl;

Accessing Databases with Rowsets

One of the most common types of controls is the rowset control. The GamesDBCtrl shown in the previous example is a simple RowSet control enhanced to return value objects. Rowset controls are based on the java.sql.RowSet interface and provide a generic mechanism for accessing database data over a network. Rowsets are derived from the java.sql.ResultSet class and inherit much of the parent behavior. Rowsets can be used to add data, query for data, traverse rows of data, and delete data.

The RowSet Wizard generates several methods; the following two methods are used to read data:

  • RowSet getAllTbleName(DatabaseFilter)—This method return all rows for a given table and is filtered based on the database filter used as input to a where clause. Note that even if no filtering is required, you must provide a DatabaseFilter.

  • RowSet detailsTbleName(key)—This method returns the requested row based on the supplied key.

Rowset data is accessed by using one of the type-specific rowset methods, a generic example of which is shown here. All rowset accessor methods use the following form:

Type getType(String ColName);

In this form, type can be String, Int, Double, Float, Short, and so on. See the java.sql.RowSet documentation for a complete list.

Rowsets can return multiple rows of data. After a select clause, rowsets are initially positioned before the first row. You can iterate over a rowset by using the next() method.

The Wonderland Casino is actually made up of a number of casinos. Descriptive data about the casinos, games, hotels, and so on is stored in a database that could be accessed by using RowSet objects. The WONDERLAND.CASINOS table contains the complete list. Its SQL definition is shown here:


Assuming you have a RowSet object that contains all the casinos, you could traverse the list using the following:

While (allData.next())
  System.out.println("ID=" + allData.getInt("ID");
  System.out.println("Name=" + allData.getString("NAME");
  System.out.println("Desc=" + allData.getString("DESCR");

Wonderland Casino Sample Data - The Wonderland Casino database definition is in the {CDROM}:\db directory on this book's CD. You can add the Wonderland database to PointBase, the database tool packaged with WebLogic Workshop, by running the mkdb.cmd command script. First, you need to edit the set-dbenv.cmd script to point to your BEA install directory. To run the script, open a command prompt, and copy the scripts to a directory where they can be edited. Edit set-dbenv.cmd and then run mkdb.cmd. Additionally, if PointBase is running somewhere other than localhost:9093/ workshop, you need to update the pbcmd.cmd script appropriately.

The use of NetUI tags to present data is covered in detail in Chapter 7. However, you could easily display the entire list of RowSet data using a netui-data:repeater tag in a JSP. Assuming you returned a rowset of data from the Casinos table defined in a Page Flow as public RowSet casinos, you could access the data as a table using the code shown in Listing 4, with important lines shaded.

Listing 4 The netui-data:repeater Tag


<netui-data:repeater dataSource="{pageFlow.casinos}">
  <table border="1">
        <netui:label value="{container.item.ID}" />
        <netui:label value="{container.item.NAME}" />
        <netui:label value="{container.item.DESCR}" />

Adding and Deleting with Rowsets

In additional to reading data, rowsets support deleting, inserting, and updating data. The Casino Maintenance department has requested adding new functionality to the Wonderland Web site to support listing, adding, and deleting casinos. A new Page Flow, CasinoMaintenance, has been added to the Wonderland application. It supports listing, adding, and deleting casino table entries. To add an entry to a rowset, do the following:

  1. Obtain a template row by using detailsTBLNameTemplate().

  2. Update the row values.

  3. Insert the new row into the rowset.

  4. Insert the rowset contents into the database.

Listing 5 shows an example of these steps.

Listing 5 The doAdd Action of CasinoMaintenanceController.jsp


  protected Forward doAdd(AddForm form)
    String name = form.name;
    String description = form.description;
    try {
      RowSet newCasino = casinosdb.detailsCasinosTemplate();
      newCasino.insertRow(); // add the row into the rowset
      casinosdb.insertCasinos(newCasino); // add the row into the db
    } catch(SQLException sqle) {
      System.out.println("Unexpected SQLException on add:" +sqle);
    return new Forward("success");

Deleting a row from a database follows a similar pattern. To delete a row, follow these steps:

  1. Obtain a rowset containing the row based on the row's key.

  2. Set the rowset to the row you want to delete.

  3. Delete the row from the rowset.

  4. Delete the row from the database.

Listing 6 shows an example of these steps.

Listing 6 The doDelete action of CasinoMaintenanceController.jsp


  protected Forward doDelete(DeleteForm form)
    String id = form.ID;
    try {
      RowSet row = casinosdb.detailsCasinos(new Integer(id));
      row.absolute( 1 );
    } catch (SQLException sqle) {
      System.out.println("Unexpected SQLException on delete:" +sqle);
    return new Forward("success");

samsThis chapter is from BEA WebLogic Workshop 8.1, by Albert J. Saganich, Jr., et al. (Apress, 2004, ISBN: 0-672-32622-1). Check it out at your favorite bookstore today.
Buy this book now.

blog comments powered by Disqus

- Customizing Wordpress Favicons and Gravatars
- Building Corner Effects with Transparent Bac...
- 3D Graphics Technology: VRML Part I - Introd...
- Creating Visual Effects
- Web Page Design Overview
- Creating Artistic Photographs
- Working with Tools in Paint Shop Pro 8
- Using HTML Quickform for Form Processing
- Introduction to Adobe FrameMaker
- WebLogic Workshop, WebLogic Platform, and th...
- Planning the Site
- Working with Web Services
- WebLogic Workshop Application Development Ba...
- Scanning Images for Web Use
- Web Graphics Overview

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 

Developer Shed Affiliates


© 2003-2019 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials