Client Application Developer's Guide

     Previous  Next    Open TOC in new window    View as PDF - New Window  Get Adobe Reader - New Window
Content starts here

Accessing Data Services from WebLogic Workshop Applications

This chapter describes how you can use Data Service controls in WebLogic Workshop to develop client applications for Data Services Platform. The following topics are included:

 


Introduction to Data Service Controls

Data Service controls provide WebLogic Workshop applications with an easy way to access data services. When you use a Data Service control to invoke data service functions, you get information back as a data object. A data object is a unit of information as defined by the Service Data Objects (SDO) specification. For more information on SDO, see Data Programming Model and Update Framework.

In addition to the functionality discussed in this chapter, Data Service controls also provide many of the same features available through the SDO Mediator API, including:

For more information on these features, see Advanced Topics.

Data Service Controls Defined

A Data Service control is a wizard-generated Java file that can be used to add data service functions and procedures to WebLogic Workshop applications. Functions and procedures can be added to Data Service controls from data services deployed on any accessible WebLogic Server, both local or remote. The Data Service control wizard retrieves all available data service functions and procedures on the server that you specify. It then lets you choose the ones to include in your control.

If accessing data services on a remote server, metadata describing information that the service functions return (in the form of XML schema files) is first downloaded from the remote server into the current application. These schema files are placed in a schema project named after the remote application. The directory structure within the project mirrors the directory structure of the remote server. AquaLogic Data Services Platform generates interface files for the target schemas associated with the queries and the Data Service control (.jcx) file.

For AquaLogic Data Services Platform 2.5 release, the Data Service control is available with both WebLogic Workshop 8.x and Workshop for WebLogic Platform 9.2. The Workshop for WebLogic Platform 9.2 Data Service control allows you to access data services from the WebLogic Server 8.1 environment. For more information about installing and using the Data Service control 9.2, refer to Using Data Service Control 9.2 on page 7-28.

Note: All client APIs, including the Data Service control, support calling data service functions without optional parameters. Data service functions with optional parameters can be called within other data service functions or from an ad hoc query, but such functions cannot be invoked from through a Data Service control itself.

Page Flow, Web Services, Portals, Business Processes

Like Java controls, you can use a Data Service control in applications such as Web services, page flows, and WebLogic integration business processes. After applying the control to a client application, you can use the data returned from query functions in the control in your application.

This chapter describes how to use a Data Service control in a page flow-based web application. The steps for using it in Portals and other WebLogic Workshop Projects are similar.

Description of the Data Service Control (JCX) File

When you create a Data Service control, WebLogic Workshop generates a Java Control Extension (.jcx) file that contains methods based on the data service's functions, and a commented method that can be uncommented and used to pass any XQuery statements (called ad hoc queries) to the server.

Design View

The Design View tab of a Data Service control displays a graphical view of the data service methods that were selected for inclusion in the control.

Figure 7-1 Design View of a JCX File

Design View of a JCX File

Using the right-click menu, you can add or edit a control method (for example, by changing the data service function or procedure associated with the method). The right-click menu is context sensitive — it displays different items if the mouse cursor is over a method or elsewhere in the control portion of the design pane.

Source View

The Source View tab shows the source code of the Data Service control. It includes annotations defining the data service function names associated with each method. For update functions, the data service bound to the update is the data service specified by the locator attribute. For example:

locator="c:/DSP/DataServices/RTLServices/ApplOrderDetailView.ds"

The signature for the method shows its return type. The return type for a read method is an SDO object corresponding to the schema type of the data service that contains the referenced function. The SDO classes corresponding to the data services used in a Data Service control reside in the Libraries folder of the project. An interface is generated for each data service. The folder also contains a copy of the schema files associated with the functions in the JCX file.

The Java Control Extension instance is a generated file. The only time you should need to edit the source code is if you want to add a method to run an ad hoc query, as described in Using Data Service Controls for Ad Hoc Queries.

Listing 7-1 shows portions of a generated Data Service control (.jcx) file. It shows the package declaration, import statements, and data service URI used with the queries.

Listing 7-1 Java Control Extension Sample
package Controls; 

import weblogic.jws.control.*;
import com.bea.ld.control.LDControl;
import com.bea.ld.filter.FilterXQuery;
import com.bea.ld.QueryAttributes;

/**
* @jc:LiquidData application="RTLApp" urlKey="RTLApp.RTLSelfService.Controls.RTLControl"
*/
public interface RTLControl extends LDControl, com.bea.control.ControlExtension
{

/* Generated methods corresponding to stored queries.
*/

/**
*
* @jc:XDS locator="ld:DataServices/RTLServices/ApplOrderDetailView.ds" functionName="submitApplOrderDetailView"
*/
java.util.Properties[] submitApplOrderDetailView(retailer.ORDERDETAILDocument rootDataObject) throws Exception;

/**
*
* @jc:XDS locator="ld:DataServices/RTLServices/ProfileView.ds" functionName="submitArrayOfProfileView"
*/
java.util.Properties[] submitArrayOfProfileView(retailer.PROFILEDocument[] rootDataObject) throws Exception;

/**
*
* @jc:XDS locator="ld:DataServices/RTLServices/ElecOrderDetailView.ds" functionName="submitElecOrderDetailView"
*/
java.util.Properties[] submitElecOrderDetailView(retailer.ORDERDETAILDocument rootDataObject) throws Exception;

/**
*
* @jc:XDS functionURI="ld:DataServices/CustomerDB/CUSTOMER" functionName="CUSTOMER" schemaURI="ld:DataServices/CustomerDB/CUSTOMER" schemaRootElement="CUSTOMER"
*/
dataServices.customerDB.customer.CUSTOMERDocument[] CUSTOMER();

/**
< section of code removed >
*/
    /** 
*
* @jc:XDS functionURI="ld:DataServices/RTLServices/ProfileView" functionName="getProfileView" schemaURI="urn:retailer" schemaRootElement="PROFILE"
*/
retailer.PROFILEDocument[] getProfileViewWithFilter(java.lang.String p0, FilterXQuery filter);

/**
* Default method to execute an ad hoc query.
* This method can be customized to have a differnt method name (e.g. runMyQuery), or to return an SDO generated class (e.g. Customer),
* or to return the DataObject class, or to have one or both of the following two extra parameters:
* com.bea.ld.ExternalVariables and com.bea.ld.QueryAttributes
* e.g. commonj.sdo.DataObject executeQuery(String xquery, ExternalVariables params);
* e.g. commonj.sdo.DataObject executeQuery(String xquery, QueryAttributes attrs);
* e.g. commonj.sdo.DataObject executeQuery(String xquery, ExternalVariables params, QueryAttributes attrs);
*/
com.bea.xml.XmlObject executeQuery(String query);


void newMethod1();
}

Using Data Service Controls for Ad Hoc Queries

Client applications can issue ad hoc queries against data service functions. You can use ad hoc queries when you need to change the way a data service function returns data. Ad hoc queries are most often used to process data returned by data services deployed on a WebLogic Server. Ad hoc queries are especially useful when it is not convenient or feasible to add functions to an existing data service.

A Data Service control generated from a wizard has a commented ad hoc query method that can serve as a starting point for creating an ad hoc query. To create the ad hoc query, follow these steps:

  1. If you do not already have a Data Service control (JCX) file, generate one using the Data Service control wizard.
  2. Add the following lines of code in the JCX file:
  3. com.bea.xml.XmlObject executeQuery(String query);

    (Replace the function name with one that is meaningful for your application. Be default, the ad hoc query returns an XMLObject, but you can return a typed SDO or typed XMLBean class that matches the return type XML for the ad hoc query. You can also optionally supply ExternalVariables or QueryAttributes (or both) to an ad hoc query.)

    When invoking this ad hoc query function from a Data Service control, the caller needs to pass the query string (and the optional ExternalVariables binding and QueryAttributes if desired). For example, an ad hoc query signature in a Data Service control will look like the following:

    public interface MyLDControl extends LDControl, 
    com.bea.control.ControlExtension
    {
    ldcProduucerDataServices.address.ArrayOfADDRESSDocument
    adHocAddressQuery(String xquery);
    }

    The code to call this Data Service control (from a WebService JWS file, for example) would be:

    /** @common:control */
    public ldcontrol.MyLDControl myldcontrol;

    /** @common:operation */
    public ldcProduucerDataServices.address.ArrayOfADDRESSDocument
    adHocAddressQuery()
    {
    String adhocQuery =
    "declare namespace f1 = \"ld:ldc_produucerDataServices/ADDRESS\";\n" +
    "declare namespace ns0=\"ld:ldc_produucerDataServices/ADDRESS\";\n"+
    "<ns0:ArrayOfADDRESS>\n"+"{for $i in f1:ADDRESS()\n" +
    "where $i/STATE = \"TX\"\n"+" return $i}\n" +
    "</ns0:ArrayOfADDRESS>\n";
    return myldcontrol.adHocAddressQuery(adhocQuery);
    }

 


Creating Data Service Controls

This section describes the steps involved in creating a Data Service control and using it in a Web project. The general steps to create a Data Service control are:

The following sections describe each of these steps in detail.

Step 1: Create a Project in an Application

Before you can create a Data Service control in WebLogic Workshop, you must create an application and a project in the application. You can create a Data Service control in most types of WebLogic Workshop projects; most commonly, you will create them in:

Step 2: Start WebLogic Server

Make sure that the WebLogic Server that hosts the AquaLogic Data Services Platform-enabled application is running. WebLogic Server can be running locally (on the same domain as WebLogic Workshop) or remotely (on a different domain from WebLogic Workshop).

Step 3: Create a Folder in a Project

Create and name a folder in the project to hold the Data Service control by selecting a folder and right-clicking on that folder. You can also create other controls (database controls, for example) in the same folder, as needed. (WebLogic Workshop controls cannot be created at the top-level of a project directory structure. Instead, they must be created in a folder.)

Step 4: Create the Data Service Control

To create a Data Service control, start the Java Control Wizard by right-clicking on the new folder in your project and choosing New Arrow symbol Java Control as shown in Figure 7-2. (You can also create a control using the File Arrow symbol New Arrow symbol Java Control menu item.)

Figure 7-2 Create a New Data Service Control

Create a New Data Service Control

Next, select Data Services Platform from the New Java Control dialog as shown in Figure 7-3. Enter a filename for the control (.jcx) file and click Next.

Figure 7-3 New Java Control Dialog

New Java Control Dialog

Step 5: Enter Connection Information for WebLogic Server

The New Java Control - AquaLogic Data Services Platform dialog (Figure 7-4) allows you to enter connection information for the WebLogic Server that hosts your Data Services Platform application or project. If the server is local, a Data Service control uses the connection information stored in the application properties. (To view these settings, access the Tools Arrow symbol Application Properties menu item in WebLogic Workshop.)

If the server is remote, choose the Remote option and fill in the appropriate server URL, user name, and password.

Note: You can specify a different username and password with which to connect to a local machine in the Data Service control Wizard as well. To do this, click the Remote button and enter the connection information (with a different username and password) for your local machine. The security credentials specified through the Application Properties or through the Data Service control wizard are used for creating the JCX file only, not for testing queries through the control. For more details, see Security Considerations When Using Data Service Controls.

When the information is correct, click Create to go to the next step.

Figure 7-4 Data Service Control Wizard: Connection Information

Data Service Control Wizard: Connection Information

Step 6: Select Data Service Functions to Add to Your Control

In the Select Data Service functions... page, select the data service functions you want to use in your application from the left pane and click Add (Figure 7-5). When done, click Finish. At that point, your Data Service control JCX file is generated, containing a call for each selected function.

Figure 7-5 Control Wizard: Select Data Service Functions Dialog Box

Control Wizard: Select Data Service Functions Dialog Box

The control appears with the functions you chose.

Each method in the file returns an SDO type corresponding to the appropriate (or corresponding) data service schema. The SDO classes are stored in the Libraries directory of the WebLogic Workshop Application.

If not already present, the LiquidDataControl.jar file is copied into the Libraries directory of your application when you create your Data Service control.

Note: If you get a timeout error when attempting to create a Data Service control, you may see a message related to the compiler being unable to find the XMLBean class for a particular schema element.
Note: You can change the timeout value — by default that value is set at 5000 (5 seconds) — by adding a directive in the WebLogic Workshop configuration file:
Note:  <beahome>/weblogic81/workshop/workshop.cfg
Note: For example to change the setting to 10000 add the following directive to the file:
 -Dcom.bea.ld.control.notification.timeout=10000

 


Modifying Existing Data Service Controls

This section describes the ways you can modify an existing Data Service control. When you edit a control, the SDO classes that are available to the control are recompiled, which means that any changes to data service are incorporated to the controls at that point as well.

This section contains the following procedures:

Changing a Method Used by a Control

To change a data service function in a Data Service control, perform the following steps:

  1. In WebLogic Workshop, open the Design View for a Data Service control (.jcx) file.
  2. Select the method you want to change, right-click, and select Edit in source view to bring up the source editor (Figure 7-6.).
  3. Figure 7-6 Changing a Function in a Data Service Control


    Changing a Function in a Data Service Control

  4. In Source View, change the comment for the function in the following ways:
    • Change the functionName value to the new function you want to use.
    • If necessary, change the functionURI value as well. This should be the path to the data service that contains the function.
    • Change the return type, parameters, and name of the function, as needed.

When you save your changes, the SDO classes based on the control are automatically recompiled.

Adding a New Method to a Control

To add a new method to an existing Data Service control, perform the following steps:

  1. In WebLogic Workshop, open an existing control in Design View.
  2. In the control Design View, move your mouse inside the box showing the control methods, right-click, then select Add Method as shown in Figure 7-7.
  3. Figure 7-7 Adding a Method to a Control


    Adding a Method to a Control

  4. Enter a name for the new method.
  5. Right-click the new method, and select Edit in source view to bring up the source editor.
  6. In the Source View, add a comment for the function. Change the functionName value to the new function you want to use. If necessary, change the functionURI value as well. This should be the path to the data service that contains the function.
  7. Change the return type, parameters, and name of the function.

Updating an Existing Control When Schemas Change

If any of the schemas corresponding to any methods in a Data Service control change, you must clean and re-build the AquaLogic Data Services Platform data service folders to regenerate the SDO classes. If the changes result in a different return type for any of the functions, you must also modify the function in the control.

Note: If you developed a client application using a static client API (mediator API or control) and you modify any schemas, you must recompile and redeploy the application, using the re-generated classes.

When you edit the control, its SDO classes are automatically regenerated.

Note: For details on working with static and dynamic SDO see Static and Dynamic SDO APIs.

 


Caching Considerations When Using Data Service Controls

The following scenario is very common: most of the time you can use cached data because it changes infrequently; however, on occasion, your application must fetch data directly the data source. At the same time, you want to update your cache with the most up-to-date information. A typical example would be to refresh the cache at the beginning of every week or month.

You can accomplish this by passing the attribute GET_CURRENT_DATA with your function call.

Bypassing the Cache When Using a Data Service Control

To bypass the data in a cached query function result, your application will need to signal Liquid Data to retrieve results directly from the data source, rather than from its cache. The steps required to accomplish this include:

Cache Bypass Example When Using a Data Service Control

Listing 7-2 shows example Java Page Flow (JPF) code that tests whether the user has requested a bypass of any cached data. If refreshCache is set to False then cached data (if any is available) is used. Otherwise the function will be invoked with the GET_CURRENT_DATA attribute and data will be retrieved from the data source. As a by-product, any cache is automatically refreshed.

Listing 7-2 Cache Bypass Example When Using Data Services Platform Control
     if (refreshCache == false) {
customerDocument = LDControl.getCustomerProfile(CustomerID);
} else {
QueryAttributes attr = new QueryAttributes();
attr.enableFeature(QueryAttributes.GET_CURRENT_DATA);
customerDocument =
LDControl.getCustomerProfileWithAttr(CustomerID, attr);
}

As mentioned above, an additional function is also needed in the your Liquid Data control JCX file. For the code shown in Listing 7-2, you would add the following definition to your Liquid Data control:

/**
* @jc:XDS functionURI="ld:DataServices/CustomerProfile" functionName="getCustomerProfile"
*/
CUSTOMERPROFILEDocument getCustomerProfileWithAttr (java.lang.String p0, QueryAttributes attr);

 


Security Considerations When Using Data Service Controls

This section describes security considerations for applications using a Data Service control. The following sections are included:

Security Credentials Used to Create Data Service Controls

The WebLogic Workshop Application Properties (Tools Arrow symbolApplication Properties) allow you to set connection information to connect to the domain in which you are running. You can either use the connection information specified in the domain boot.properties file or override that information with a specified username and password.

When you create a Data Services Platform control JCX file and are connecting to a local Data Services Platform server (Data Services Platform on the same domain as WebLogic Workshop), the user specified in the Application Properties is used to connect to the Data Services Platform server. When you create a Data Service control and are connecting to a remote Data Services Platform server (a WebLogic Server on a different domain from WebLogic Workshop), you specify the connection information in the Data Service control wizard connection information dialog (see Figure 7-4).

When you create a Data Service control, the Control Wizard displays all queries to which the specified user has access privileges. The access privileges are defined by security policies set on the queries, either directly or indirectly.

Note: The security credentials specified through the Application Properties or through the Data Service control wizard are only used for creating the Data Service control JCX file, not for testing queries through the control. To test a query through the control, you must get the user credentials either through the application (from a login page, for example) or by using the run-as property in the Web service file.

Testing Controls With the Run-As Property in the JWS File

You can use the run-as property to test a control running as a specified user. To set the run-as property in a Web service, open the Web service and enter a user for the run-as property in the WebLogic Workshop property editor.

When a query is run from an application, the application must have a mechanism for getting the security credential. The credential can come from a login screen, it can be hard-coded in the application, or it can be imbedded in a J2EE component (for example, using the run-as property in a JWS Web service file).

Trusted Domains

If the WebLogic Server that hosts the AquaLogic Data Services Platform project is on a different domain than WebLogic Workshop, then both domains must be set up as trusted domains.

Domains are considered trusted domains if they share the same security credentials. With trusted domains, a user known to one domain need not be authenticated on another domain, if the user is already known on that domain.

Note: After configuring domains as trusted, you must restart the domains before the trusted configuration takes effect.

Configuring Trusted Domains

To configure domains as a trusted user, perform the following steps:

  1. Log into the WebLogic Administration Console as an administrator.
  2. In the left-frame navigation tree, click the node corresponding to your domain.
  3. At the bottom of the General tab for the domain configuration, click the link labeled View Domain-wide Security Settings Links.
  4. Click the Advanced tab. (See Figure 7-8.)
  5. Figure 7-8 Setting up Trusted Domains


    Setting up Trusted Domains

  6. Uncheck the Enable Generated Credential box, enter and confirm a credential (usually a password), and click Apply.
  7. Repeat this procedure for all of the domains you want to set up as trusted. The credential must be the same on each domain.

For more details on WebLogic security, see:

For information on security, see:

 


Using Data Services Platform with NetUI

The WebLogic NetUI tag library allows you to rapidly assemble JSP-based applications that display data returned by Data Services Platform. The following sections list the basic steps for using NetUI to display results from a Data Service control:

Generating a Page Flow From a Control

When you use WebLogic Workshop to generate a page flow, WebLogic Workshop creates the page flow, a start page (index.jsp), and a JSP file and action for each method you specify in the Page Flow wizard.

To Generate a Page Flow From a Data Service Control

Perform the following steps to generate a page flow from a Data Services Platform control.

  1. Select a Data Services Platform control JCX file from the application file browser, right-click, and select Generate Page Flow.
  2. In the Page Flow Wizard (see Figure 7-9), enter a name for your Page Flow and click Next.
  3. Figure 7-9 Enter a Name for the Page Flow


    Enter a Name for the Page Flow

  4. On the Page Flow Wizard - Select Actions dialog, check the methods for which you want a new page created. The wizard has a check box for each method in the control. (See Figure 7-10.)
  5. Figure 7-10 Choose Data Services Platform Methods for the Page Flow


    Choose Data Services Platform Methods for the Page Flow

  6. Click Create.
  7. WebLogic Workshop generates the Java Page Flow (JPF file), a start page (index.jsp), and a JSP file for each method you specify in the Page Flow wizard.

  8. Add and initialize variables to the JPF file based on the SDO classes. For details, see Adding Service Data Objects (SDO) Variables to the Page Flow.
  9. Drag and drop the SDO variables to your JSPs to bind the data from Data Services Platform to your page layout. For details, see Displaying Array Values in a Table or List.
  10. Build and test the application in WebLogic Workshop.

Adding a Data Service Control to an Existing Page Flow

You can add a Data Service control to an existing Page Flow JPF file. The procedure is the same as adding a Data Service control to a Web service as described in the section Adding a Data Service Control to a Web Service in Enabling AquaLogic Data Services Applications for Web Service Clients. However, instead of opening the Web service in Design View as described in that chapter, you open the Page Flow JPF file in Action View.

You can also add a control to an existing page flow from the Page Flow Data Palette (available in Flow View and Action View of a Page Flow) as shown in Figure 7-11.

Figure 7-11 Adding a Control to a Page Flow from the Data Palette

Adding a Control to a Page Flow from the Data Palette

Adding Service Data Objects (SDO) Variables to the Page Flow

To use the NetUI features to drag and drop data into a JSP, you must first create one or more variables in the page flow JPF file. The variables must be of the data object type corresponding to the schema associated with the query.

Note: A data object is the fundamental component of the SDO architecture. For more information, see Data Programming Model and Update Framework.

Defining a variable in the page flow JPF file of the top-level class of the SDO function return type provides you access to all the data from the query through the NetUI repeater wizard. The top-level class, which corresponds to the global element of the data service type, has "Document" appended to its name, such as CUSTOMERDocument.

When you create a Data Service control and the SDO variables are generated, an array is created for each element in the schema that is repeatable. You may want to add other variables corresponding to other arrays in the classes to make it more convenient to drag and drop data onto a JSP, but it is not required. For example. when an array of CUSTOMER objects can contain an array of ORDER objects, you can define two variables: one for the CUSTOMER array and one for the ORDER array. You can then drag the variables to different JSP pages.

Define each variable with a type corresponding to an SDO object. Define the variables in the source view of the page flow controller class. The variables should be declared public. In the following example, the bold-typed variable declarations show an example of user variable declarations:

public class CustomerPFController extends PageFlowController
{
/**
* This is the control used to generate this pageflow
* @common:control
*/
private DanubeCtrl myControl;

public CUSTOMERDocument var;
public POITEM currentItem;
public PAYMENTListDocument payments;

Once defined in the page flow controller, the variables appear on the Data Palette tab. From there, you can drag-and-drop them onto JSP files. When you drag-and-drop an array onto a JSP file, the NetUI Repeater Wizard appears and guides you through selecting the data you want to display. (See Figure 7-12.)

Figure 7-12 Page Flow Variables for XMLBean Objects

Page Flow Variables for XMLBean Objects

To populate the variable with data, initialize the variable in the page flow method corresponding to the page flow action that calls the query. For details, see Initializing a Variable in the Page Flow.

Adding a Variable to a Page Flow

Perform the following steps to add a variable to the page flow:

  1. Open your Page Flow JPF file in WebLogic Workshop.
  2. Open the Source View tab.
  3. In the variable declarations section of your Page Flow class, enter a variable with the SDO type corresponding to the schema elements you want to display. Depending on your schema, what you want to display, and how many queries you are using, you might need to add several variables.
  4. To determine the SDO type for the variables, examine the method signature for each method that corresponds to a query in the Data Service control. The return type is the root level of the SDO class. Create a variable of that type. For example, if the signature for a control method is:
  5. org.openuri.temp.schemas.customer.CUSTOMERDocument getCustomer(int p1); 

    Create a variable as follows:

    public org.openuri.temp.schemas.customer.CUSTOMERDocument var; 
  6. After you create the variables, initialize them as described in the following section.

Initializing a Variable in the Page Flow

You can initialize a variable by calling a function in a Data Service control, which will populate the variable with the returned data. Initializing the variables ensures that the data bindings to the variables work correctly and that there are no tag exceptions when the JSP displays the results the first time.

Perform the following steps to initialize the variables in Page Flow:

  1. Open your Page Flow JPF file in WebLogic Workshop.
  2. Open the Source View.
  3. In the page flow action that corresponds to the Data Services Platform query for which you are going to display the data, add the code to initialize the variable.

The following example shows how to initialize an object on the Page Flow. The code (and comments) in bold has been added. The rest of the code was generated when the Page Flow was created from the Data Service control (see Generating a Page Flow From a Control).

public class CustomerPFController extends PageFlowController
{
/**
* This is the control used to generate this pageflow
* @common:control
*/
private DanubeCtrl myControl;

public CUSTOMERDocument var;
...
/**
* Action encapsulating the control method :getCustomer
* @jpf:action
* @jpf:forward name="success" path="viewCustomer.jsp"
* @jpf:catch method="exceptionHandler" type="Exception"
*/
public Forward getCustomer(GetCustomerForm aForm)
throws Exception
{
var = myControl.getCustomer(aForm.p1);
...
return new Forward("success");
}
}

Working with Data Objects

After creating and initializing a data objects as a public variable in the Page Flow, you can drag and drop elements of the object onto your application pages (such as JSPs) from the Data Palette.

The elements appear in dot-delimited chain format, such as:

	pageFlow.var.CUSTOMER.CUSTOMERNAME

Notice that the function that actually returns the element value is getCUSTOMERNAME(), which returns a java.lang.String value, the name of a customer.

As you edit code in the source view, WebLogic Workshop offers code completion for method and member names as you type. A selection box of available elements appears in the data object variable as shown in Figure 7-13.

Figure 7-13 DataObject Method Name Completion

DataObject Method Name Completion

Note: For more information on programming with AquaLogic Data Services Platform data objects, see Data Programming Model and Update Framework.

Displaying Array Values in a Table or List

AquaLogic Data Services Platform maps to an array any data element specified to have unbounded maximum cardinality in its XML schema definition. Unbounded cardinality means that there can be zero to many (unlimited) occurrences of the element (indicated by an asterisk in the return type view of the DSP Console).

When you drag and drop an array value onto a JSP File, BEA WebLogic Workshop displays the Repeater wizard to guide you through the process of selecting the data you want to display. The Repeater wizard provides choices for displaying the results in an HTML table or in a list.

Adding a Repeater to a JSP File

To add a NetUI repeater tag (used to display the data from a Data Services Platform query) to a JSP file, perform the following steps:

  1. Open a JSP file in your Page Flow project where you want to display data. This should be the page corresponding to the action in which the variable is initialized.
  2. In the Data Palette Arrow symbolPage Flow Properties, locate the variable containing the data you want to display.
  3. Expand the nodes of the variable to expose the node that contains the data you want to display. If the variable does not traverse deep enough into your schema, you will have to create another variable to expose the part of your schema you require. For details, see Initializing a Variable in the Page Flow.
  4. Select the node you want, then drag and drop it onto the location of the JSP file in which you want to display the data. You can do this either in Design View or Source View. WebLogic Workshop displays the repeater wizard as shown in Figure 7-14.
  5. Figure 7-14 Repeater Wizard


    Repeater Wizard

  6. In the repeater wizard, navigate to the data you want to display and uncheck any fields that you do not want to display. There might be multiple levels in the repeater tag, depending on your schema.
  7. Click Next. The Select Format screen appears as shown in Figure 7-15.
  8. Figure 7-15 Repeater Wizard Select Format Screen


    Repeater Wizard Select Format Screen

  9. Choose the display format for your data and click Create.
  10. Right-click on the JSP page and choose Run Page to see the results.

Adding a Nested Level to an Existing Repeater

You can create repeater tags inside other repeater tags. You can display nested repeaters on the same page (in nested tables, for example) or you can set up Page Flow actions to display the nested level on another page (with a link, for example).

To create a nested repeater tag, perform the following steps:

  1. Add a repeater tag as described in Adding a Repeater to a JSP File.
  2. Add a column to the table where you want to add the nested level.
  3. Drag and drop the array from your variable corresponding to your nested level into the data cell you created in the table.
  4. In the repeater wizard, select the items you want to display.
  5. Click the Create button in the repeater wizard to create the repeater tags.
  6. Right-click on the JSP page and choose Run Page to see the results.

Adding Code to Handle Null Values

It is a common JSP design pattern to add conditional code to handle null checks. If you do not check for null values returned by function invocations, your page will display tag errors if it is rendered before the functions on it are executed.

To add code to handle null values, perform the following steps:

  1. Add a repeater tag as described in Adding a Repeater to a JSP File.
  2. Open the JSP file in source view.
  3. Find the netui-data:repeater tag in the JSP file.
  4. If the dataSource attribute of the netui-data:repeater tag directly accesses an array variable from the page flow, then you can set the defaultText attribute of the netui-data:repeater tag. For example:
  5. <netui-data:repeater dataSource="{pageFlow.promo}" defaultText="no data">

    If the dataSource attribute of the netui-data:repeater tag accesses a child of the variable from the page flow, you must add if/else logic in the JSP file as described below.

  6. If the defaultText attribute can have a null value for your netui-data:repeater tag, add code before and after the tag to test for null values. The following is sample code. The code in bold is added, the rest is generated by the repeater wizard. This code uses the profile variable initialized in Initializing a Variable in the Page Flow.
  7. <%                                         
    PageFlowController pageFlow = PageFlowUtils.getCurrentPageFlow(request);
    if ( ((pF2Controller)pageFlow).profile == null
    || ((pF2Controller)pageFlow).profile.getPROFILEVIEW().getCUSTOMERPROFILEArray() == null
    || ((pF2Controller)pageFlow).profile.getPROFILEVIEW().getCUSTOMERPROFILEArray().length == 0){
    %>
             <p>No data</p>
             <% } else {%>
    <netui-data:repeater dataSource=
            "{pageFlow.profile.PROFILEVIEW.CUSTOMERPROFILEArray}">
    <netui-data:repeaterHeader>
    <table cellpadding="2" border="1" class="tablebody" >
    <tr>
    <!- the rest of the table and NetUI code goes here -->
    <td><netui:label value
          ="{container.item.PROFILE.DEFAULTSHIPMETHOD}"></netui:label></td>
    </tr>
    </netui-data:repeaterItem>
    <netui-data:repeaterFooter></table></netui-data:repeaterFooter>
    </netui-data:repeater>
             <% }%>
  8. Test your application.

 


Using Data Service Control 9.2

Data Service control 9.2 is a custom Java control accessible through BEA Workshop for WebLogic Platform 9.2, which allows easy access to data services deployed on WebLogic Server 8.1, from other components of Workshop for WebLogic Platform 9.2 application, such as Java Web Service (JWS).

For AquaLogic Data Services Platform 2.5 release, the control acts as a bridge between the 9.2 based Workshop for WebLogic Platform client and 8.x AquaLogic Data Services Platform server.

Note: With the 9.2 release, WebLogic Workshop has been renamed to Workshop for WebLogic Platform. In this section, the term Workshop for WebLogic Platform is used to refer to the 9.2 environment.

The Data Service control is based on the open source beehive control architecture. Beehive control is an Apache Software Foundation project that provides a programming model for designing business functionality that makes it easy to use lightweight JavaBeans and declarative configuration through JDK 1.5 annotations. For more information about beehive controls, refer to:


http://beehive.apache.org/docs/1.0/controls/programming.html

Figure 7-16 illustrates the Data Service control 9.2 architecture, which is based on the beehive control architecture. The Data Service control implementation files in 9.2 use the beehive runtime environment to interface with WebLogic Server 8.1.

Figure 7-16 AquaLogic Data Services Platform 9.2 Control Architecture

AquaLogic Data Services Platform 9.2 Control Architecture

Data Service control 9.2 consists of the core control infrastructure classes and the Wizard classes, which are used to create the Data Service control. This section describes the features of Data Service control 9.2 and provides steps to use it for accessing data services deployed on WebLogic Server 8.1. It includes the following topics:

Differences Between the 9.2 and 8.1 Data Service Control

The data service control is created in Workshop for WebLogic Platform and is similar to the control available with the AquaLogic Data Services Platform 8.1 environment. However, there are some differences in functionality, which include:

Installing the Data Service Control 9.2 Plug-In

Data Service control 9.2 is available as a plug-in with Workshop for WebLogic Platform 9.2. The control is packaged in the com.bea.dsp.control.wizard.zip file, which you need to unzip into the following location:

<BEA_HOME>/workshop92/workshop4WP/eclipse

After you unzip the file, the com.bea.dsp.control.wizard_1.0.0 directory is created in the following location:

<BEA_HOME>/workshop92/workshop4WP/eclipse/plugins/

Setting Up WebLogic Server 8.1 to Use Data Service Control 9.2

For using the Data Service control 9.2, both the 8.1 and 9.2 WebLogic Servers should be running. In addition, you need to configure the classpath of WebLogic Server 8.1 to include wls90interop.jar, as follows:

  1. Go to <BEA_HOME>\weblogic81\samples\domains\ldplatform.
  2. Open the setDomainEnv.cmd file for editing and search for the PRE_CLASSPATH variable.
  3. Add the path to the wls90interop.jar file to the PRE_CLASSPATH variable and save the file. This file is located in the <BEA_HOME>\liquiddata\lib directory.
Note: WebLogic Server8.1 is the server where the AquaLogic Data Services Platform application is deployed.

Using Data Service Control 9.2 from Workshop for WebLogic Platform

After installing the control plug-in, you can create the control in Workshop for WebLogic Platform and use it to access data from AquaLogic Data Services Platform. This section provides the steps to create, edit, consume, delete, and uninstall the control. It includes the following topics:

Creating and Using the Data Service Control

After the control plug-in is installed in the 9.2 environment, it is accessible through Workshop for WebLogic Platform 9.2 environment.

To use the Data Service control, you need to:

  1. Create a Web service project.
  2. Include a Java package in the project, which in turn contains the Data Service control file.
  3. Create a JWS, which will use the Data Service control 9.2 to access data services from WebLogic Server 8.1.

This section describes in more detail the steps needed to create the Web service project and then use the control through JWS.

Creating a Web Service Project

The Web service project requires some facets installed for the Data Service control to work, which are:

If these facets are not installed with the Web Service project, then an error message is displayed as shown in Figure 7-17:

Figure 7-17 Error Message

Error Message

To create the Web Service project, perform the following steps:

  1. Click StartArrow symbolAll ProgramsArrow symbolBEA Products (BEA HOME)Arrow symbolWorkshop for WebLogic Platform.
  2. In Workshop for WebLogic Platform, click File Arrow symbolNewArrow symbolProject and select Web Service Project as shown in Figure 7-18.
  3. Figure 7-18 New Project: Select a Wizard Dialog Box


    New Project: Select a Wizard Dialog Box

  4. Click Next and specify the project name in the Project Name box of the New Web Service Project dialog box as shown in Figure 7-19.
  5. Select the Add Project to an EAR check box to create the EAR for the Web service project. The EAR represents the AquaLogic Data Services Platform application, which is deployed on the WebLogic Server 8.1.
  6. Figure 7-19 New Web Service Project Dialog Box


    New Web Service Project Dialog Box

  7. Click Next and in the Select Project Facets dialog box, the Beehive Controls option is selected by default. You also need to select XMLBeans Builder as shown in Figure 7-20.
  8. Figure 7-20 New Web Service Project: Select Project Facets


    New Web Service Project: Select Project Facets

  9. Click Next and specify the name of the Web module as shown in Figure 7-21. This module is created in the default WebContent folder that is created with the Web Service project.
  10. Note: If a folder with the same name exists, you are prompted to provide a different name.
    Figure 7-21 New Web Service Project: Web Module Dialog Box


    New Web Service Project: Web Module Dialog Box

  11. In the Web Module dialog box, retain the default selection in this dialog box, then click Next.
  12. In the XMLBeans Builder dialog box, click the XMLBeans Option tab and select the "Include project classpath entries in classpath for XMLBeans compilation" check box, as shown in Figure 7-22. Click Finish.
  13. Figure 7-22 New Web Service Project: XMLBeans Builder Dialog Box


    New Web Service Project: XMLBeans Builder Dialog Box

    The new Web service project (DSPCtrl_Test) and EAR (DSPCtrl_EAR) are created in Workshop for WebLogic Platform 9.2, as displayed in Figure 7-23. The EAR is the same as the application in AquaLogic Data Services Platform 8.1 environment.

    Figure 7-23 New Web Service Project and EAR


    New Web Service Project and EAR

  14. After creating the Web service project, create the package in which the Data Service control will be wrapped, as follows:
    1. Right-click the src folder in the Web service project and select NewArrow symbolPackage to display the New Java Package dialog box.
    2. Enter the name of the Java package, such as com.bea.dspctrltest, in the Name field and click Finish.
    3. The package is created under the <WebServiceProject>/src/ directory in Workshop for WebLogic Platform.

Creating Data Service Control

To create the Data Service control in Workshop for WebLogic Platform:

  1. Right-click the package com.bea.dspctrltest you created and select NewArrow symbolOthersArrow symbolControls.
  2. Select AquaLogic Data Services Platform Controls from the Select a wizard dialog box and click Next, as shown in Figure 7-24.
  3. Figure 7-24 Select a Wizard Dialog Box


    Select a Wizard Dialog Box

  4. In the New DSP Control Creation dialog box displayed in Figure 7-25
    1. Enter the location where you want to create the control in the Container field.
    2. Enter the name of the control in the File name field.
    3. Figure 7-25 New DSP Control Creation Dialog Box


      New DSP Control Creation Dialog Box

      Note: A Data Service control can be created only in a Web service project.
  5. In the Select Control Attributes dialog box (Figure 7-26), specify the URL of the WebLogic Server where the AquaLogic Data Services Platform application is deployed, along with the user name and password for connecting to the server. The URL should be in the following format:
  6. t3://<ALDSPServerName>:<PortNum>

    where,

    <ALDSPServerName> is the WebLogic Server 8.1 where the AquaLogic Data Services Platform application is deployed.

    <PortNum> is the port number of the WebLogic Server 8.1.

  7. Click Get Application List for a list of data services deployed on the server and click Next.
  8. Figure 7-26 Select Control Attribute


    Select Control Attribute

  9. In the Method Selection Page dialog box (Figure 7-27), select the data services, which you want to access and click Add. These data services will now be accessible through the WebLogic 9.2 environment.
  10. Figure 7-27 Method Selection Page Dialog Box


    Method Selection Page Dialog Box

  11. Now, click Finish. This completes the task of creating the Data Service control in Workshop for WebLogic Platform.

After you create the Data Service control 9.2, several operations automatically occur:

Note: When creating or working with any non-data service project, you should add a copy of the sdo.xsdconfig file to the root directory of your project. This file can be found in the root directory of any data service-based project.

For example, if you have a schemas project, you should add the sdo.xsdconfig file to its root directory to avoid name collisions between the XMLBean generated by an SDO-based project and an XMLBean-based project.
Creating the JWS and Using the Data Service Control

You can use the 9.2-level data service control through a JWS. To create the JWS:

  1. Right-click the com.bea.dspctrltest Java package that you created earlier and select New Arrow symbolWebLogic Web Service. Specify the name of the JWS project in the File Name field as displayed in Figure 7-29.
  2. Figure 7-29 New Java Web Service


    New Java Web Service

  3. Click Finish. This creates the Java Web service as shown in Figure 7-30, which will use Data Service control to access data services.
  4. Figure 7-30 Java Web Service


    Java Web Service

  5. Right-click in the JWS file tab (dspctrlJWS.java) and select InsertArrow symbolControl (Figure 7-31) to display the Select Control dialog box.
  6. Figure 7-31 Adding Data Service Control to JWS


    Adding Data Service Control to JWS

  7. The DSPCtrl_Test control that you created earlier is displayed in the Existing Project Controls list. Select this control and click OK. This creates the Control annotation (@Control) in the WebServices annotation and declares the control variable, as shown in Figure 7-32.
  8. Figure 7-32 Control Annotation


    Control Annotation

  9. You can now invoke any method for the data services that you selected for the control. In this case, the CUSTOMER() has been invoked, as shown in Figure 7-33.
  10. Figure 7-33 Invoking a Method through Data Service Control


    Invoking a Method through Data Service Control

  11. To run the method on the server, right-click in the window and select Run As Arrow symbolRun on Server to display the Run on Server dialog box (Figure 7-34).
  12. Figure 7-34 Run on Server Dialog Box


    Run on Server Dialog Box

  13. Select the 9.2 WebLogic Server and click Next. In the Add and Remove Projects dialog box, the project EAR contains the control. If there are any other EARs, which you do not want to run on the server, you should remove them from the list, and then click Finish.
  14. The WebLogic Server 9.2 is started and the application opens up in the Workshop Test Browser, as shown in Figure 7-35.

    Figure 7-35 Workshop Test Browser


    Workshop Test Browser

  15. Now, you can execute the hello() method, by clicking hello in the test browser. The server response is displayed, as shown in Figure 7-36.
  16. Figure 7-36 Response for the Hello Method


    Response for the Hello Method

Modifying and Uninstalling the Control

This section provides the steps to edit, delete, and uninstall the Data Service control.

Editing and Deleting the Data Service Control

To edit the Data Service control, right-click the data service control file (DSPCtrl_DSPControlFile.java), and select Edit ControlArrow symbolEdit DSP Control, as shown in Figure 7-37.

Figure 7-37 Editing the Data Service Control

Editing the Data Service Control

To delete the Data Service control 9.2, right-click the control file and select Delete.

Uninstalling the Control

To uninstall the control:

  1. Go to the directory where you installed the control, which is set to:
  2. <BEA_HOME>/workshop92/workshop4WP/eclipse/plugins/

  3. Delete the control plug-in directory, com.bea.dsp.control.wizard_1.0.0, from this location.

  Back to Top       Previous  Next