Sunday October 15, 2006
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.
If you add this web service
to Java Studio Creator, you get something like this.
If you drag the web service method "getCars" onto a table, you'll get a
table looking like this.
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.
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 a property, "engines"
of type
"Engine". Now select the "objectArrayDataProvider1" form the
Outline window and change the "array" property to be "engines"
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.
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.
Posted by david
( Oct 15 2006, 12:07:31 AM MDT )
Permalink

|

|