This tip explains how to display a two dimensional array of data in the Table Component. Creator comes bundled with dataproviders to display database table in the Table, along with other dataproviders like ObjectArrayDataProvider and ObjectListDataProvider to display data from POJOs (Plain Old Java Objects) using reflection. Unfortunately no dataprovider exists to display just a two dimensional array of data
Ex.
int[][] myData = {{1,2,3},
{4,5,6},
{7,8,9},
{10,11,12}
};
Several Creator customers have asked about this in the forum. So I decided to write a simple data provider called ArrayDataProvider. It can be invoked as
new ArrayDataProvider(array)
or
new ArrayDataProvider().setArray(array)
The two dimensional array can be of any Java primitive (int, float, double, boolean etc)
You can download the dataproviderex.jar from here and a test project ArrayDataProviderTest.zip from here.Note: when you open the test project Creator would complain that one or more libraries could not be resolved. Right click on the project and select "Resolve Reference". In the resulting dialog, give the path to the downloaded dataproviderex.jar
Steps to use ArrayDataProvider in your project
Step1:
Example MyArrayDataProvider.java
import com.sun.rave.dataprovider.ArrayDataProvider;
public class MyArrayDataProvider extends ArrayDataProvider{
int[][] myData = {{1,2,3},{4,5,6},{7,8,9},{10,11,12}};
public MyArrayDataProvider() {
setArray(myData);
}
}
Step2:
Now add the MyArrayDataProvider as property to SessionBean1.java. Right click on SessionBean1.java and select Add -> property. In the Name field enter "myArrayDataProvider". In the Type field enter "MyArrayDataProvider". The following code will appear in the SessionBean1.java
private MyArrayDataProvider myArrayDataProvider;
public MyArrayDataProvider getMyArrayDataProvider() {
return this.myArrayDataProvider;
}
public void setMyArrayDataProvider(MyArrayDataProvider myArrayDataProvider) {
this.myArrayDataProvider = myArrayDataProvider;
}
Note: This is important. Compile the project, close and reopen the project. This is a work around for the Class Loader issue that is dogging Creator 2 design time. Unless you do this the newly added class MyArrayDataProvider will not be available to Creator design time system (Ths will be fixed in the future release)
Step3:
Bingo! Table component will display your two dimensional array data as shown below