Java Studio Creator - Changing the Table Columns from A Dropped Web Service

I talked to a developer the other day that had some problems with the results of dropping a web service method on a table.  The table columns were the high level attributes of the returned values but he wanted different values to show up in the table.  This blog will show you how to dig into types returned from web services and display the pieces you want in the table columns..


First, a little about the sample web service.  I created a simple web service to return an array of type "Car".  Here is a class diagram of "Car" as well as the web service end point interface and the implementation.

uml diagram
If you add this web service to Java Studio Creator, you get something like this.

add web service


If you drag the web service method "getCars" onto a table, you'll get a table looking like this.

wrong table stuff

As you can see, the dataprovider was created from the high-level attributes of Car; body, engine, frame and model.  This is really all the code that does the data provider can do to guess at what to show.  But, suppose you really wanted to show the "engine" attributes in the table?  Here's how to do it.

First, drag and drop an "Object Array Data Provider" onto the designer.  This should create "objectArrayDataProvider1" in the Outline window.


object array data provider

At this point, we need to do some coding to fill the new dataprovider with the "engine" attributes.   Here's the code that goes in the "init" method.

public void init() {
...
 // Perform application initialization that must complete
 // \*after\* managed components are initialized
// TODO - add your own initialization code here
/\*\*
 \*  We need to build an Array from the subparts of the car to use in the dataprovider
 \*/
 ArrayList engines = new ArrayList();
 try {
boolean moreRows = myWebServiceGetCars1.cursorFirst();
RowKey currentRowKey = null;
FieldKey engineKey = myWebServiceGetCars1.getFieldKey("engine");
while(moreRows) {
currentRowKey = myWebServiceGetCars1.getCursorRow();
Engine currentEngine = (Engine)myWebServiceGetCars1.getValue(engineKey, currentRowKey);
engines.add(currentEngine);
moreRows = myWebServiceGetCars1.cursorNext();
}
} catch (DataProviderException dpe) {
error("DataProviderException=" + dpe);
}

this.objectArrayDataProvider1.setArray((Engine [])engines.toArray(new Engine [0]));
}

You could just call the web service to get the "Car" array and go through and build the Array.   You will, however, be making another call across the wire which can be expensive.  The web service data provider is created in the "_init" method called in the first part of "init".  When the web service data provider is created, it tries to make a call to the web service to fill in the data.

Now we need to add an "engine" property to the "Page1" of type Engine.  This will allow us to point our new Object Array Data Provider to it.  Add a property to Page1 by drilling down in the Project window

add property

Add a property, "engines" of type "Engine".  Now select the "objectArrayDataProvider1" form the Outline window and change the "array" property to be "engines"

change data provider


Next, select the table, right-click and select "Bind to Data".  From the "Get From Data:" dropdown, select "objectArrayDataProvider1" and press the "Apply" button.  You should see something like this.

changed table


That's it!  You've not successfully created a new data provider and used a different set of values in the web service return to populate the table.


Comments:

If I have the LicenseKey to access web services what is the code to use them? thanks

Posted by Tadas on October 19, 2006 at 06:43 PM MDT #

When I add to bean pattern property "engines" with type Engine[], I don't see this choise in the "objectArrayDataProvider1" window property "array" value. what's wrong?

Posted by Tadas B. on October 20, 2006 at 06:54 AM MDT #

I'm not sure which web service you are referring to. Each web service implementation has a different way of taking a license key but most take it as one of the parameters.

Posted by David Botterill on October 20, 2006 at 09:56 AM MDT #

"When I add to bean pattern property "engines" with type Engine[], I don't see this choise in the "objectArrayDataProvider1" window property "array" value. what's wrong?" Tadas,
Sorry I should have put webservice.mywebservice.Engine[] as the return type. Since the web service client was created in a different package, you need to specifiy the full package name of the type in the web service.
-David

Posted by guest on October 20, 2006 at 10:13 AM MDT #

Can I change the tables column but without using a web service class? The thing is, the web service I'm accessing is already defined and if I drop it to the table no field is displayed. So I had to get the fields I want to display from the web service manually and store them in an array of MyClass. But when I add the property MyClass[] its not displayed in the property "array" value.

Posted by Adrian on May 22, 2007 at 02:00 AM MDT #

Adrian, There is a defect in Creator for this. After you define the getters and setters for the type "MyClass[]", you need to close and reopen the project to have it recognized in the "array" type.

Posted by David on May 24, 2007 at 04:16 AM MDT #

Post a Comment:
  • HTML Syntax: NOT allowed
About

David Botterill

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today