Why can I not find an example...

...of how to create a java bean that provides data to a table component? There is an existing example in the Travel Center stuff but no where can I find source code for this example, or an explanation of how to do it. I want to provide tabular data that did NOT COME FROM A DATABASE!!!!

This should be simple (I suspect it won't be) but whether it is or not it is such a FUNDAMENTAL task that it should be clearly defined and highlighted. I've been hunting for a week now, and I'm normally really good at finding what I need.

Any ideas where I can find such an example?

Help!

[603 byte] By [RobertHouben] at [2007-11-26 11:57:14]
# 1

Take a look at http://developers.sun.com/prodtech/javatools/jscreator/learning/tutorials/2/hib ernate.html#object. This shows how to wrap a list of objects. In this example, the array is output from a database class, but you can use an Array List of your beans in a similar way. Then look at http://developers.sun.com/prodtech/javatools/jscreator/learning/tutorials/2/hib ernate.html#08 for binding a table to your custom data provider.

You might also want to look at http://blogs.sun.com/divas/entry/table_component_sample_project. This is the sample project that is going to be used for an upcoming tutorial (but we have a backlog of tutorials so it won't be out soon). Unfortunately, it does not offer the explanation that you are looking for, but it does have the source code that you can look at. The table in this sample project wraps a JavaBean class.

jetsons at 2007-7-7 12:17:14 > top of Java-index,Development Tools,Java Tools...
# 2

Thanks for the info. This is getting me closer, but I still have a fundamental problem. Lets say that I have 3 values that I need to construct on-the-fly, for 4 situations, so I have 3 columns, 4 rows AND NO JDBC DRIVER ANYWHERE.

Note, I do not EVER have a rowset object of any sort. How do I construct this? I don't think ArrayList gives me a 2-dimensional result.

The example you point me at takes items from a Trip class which it does not appear to give me source for. I'm guessing a Trip is a wrapped RowSet. That doesn't work for me unless there's an easy way to construct one without requiring a JDBC driver.

Again, is there an example somewhere that says, "Here is how you provide data that didn't come from JDBC to a Table object"?

This has to be a simple task. I can't believe that it is that uncommon that no one has run into the need to do this. Or maybe my need to get data from strange sources is unique! ;)

TIA,

RobertHouben at 2007-7-7 12:17:14 > top of Java-index,Development Tools,Java Tools...
# 3

Robert,

As I said before, the first tutorial shows a step by step for creating your own data provider. I acknowledged that this was for an array of data that comes from a database, but you can apply the knowledge to any ArrayList.

I then pointed you to the sample project that binds the data provider to an array of JavaBean objects. That is what you said you wanted to do. The JavaBean provides the 3rd dimension (the columns). So I will bring the mountain to you and post the code for the custom data provider. In this sample, I hard code the JavaBean objects but I assume you would know how to modify the code to fill it up with your data. If you want to know what the table looks like or what the JavaBean class looks like, go to the blog.

import com.sun.data.provider.impl.ObjectListDataProvider;

import java.util.ArrayList;

import java.util.List;

/**

*

* @author localuser

*/

public class FoodListDataProvider extends ObjectListDataProvider{

private List foodList = new ArrayList();

/** Creates a new instance of foodListDataProvider */

public FoodListDataProvider() {

foodList.add(new FoodItem("20100", "2000", "macaroni, cooked",

"Macaroni, cooked, enriched",

'Y', 0, "", 45, 21, 81, 5, 14

));

foodList.add(new FoodItem("20345", "2000", "rice, white",

"Rice, white, long-grain, regular, cooked, enriched, with salt",

'Y', 0, "", 194, 35, 88, 3, 9));

foodList.add(new FoodItem("11027", "1100", "bamboo shoots",

"Bamboo shoots, cooked, boiled, drained, without salt",

'N', 0, "", 25, 5, 60, 18, 22));

foodList.add(new FoodItem("11053","1100", "beans, green",

"Beans, snap, green, cooked, boiled, drained, without salt",

'Y', 0, "", 44, 10, 80, 7, 13));

foodList.add(new FoodItem("11109", "1100", "cabbage, raw",

"Cabbage, raw",

'Y', 20, "Brassica oleracea (Capitata Group)", 21, 7, 81, 4, 15));

foodList.add(new FoodItem("11091", "1100", "broccoli, cooked",

"Broccoli, cooked, boiled, drained, without salt",

'Y', 0, "", 44, 8, 64, 10, 26));

foodList.add(new FoodItem("11124","1100","carrots, raw",

"Carrots, raw",

'Y', 11, "Daucus carota", 52, 12, 89, 5, 6));

foodList.add(new FoodItem("09003","0900","apples, raw",

"Apples, raw, with skin",

'Y', 8, "Malus domestica", 65, 15, 95, 3, 2));

foodList.add(new FoodItem("09037","0900", "avocados, raw",

"Avocados, raw, all commercial varieties",

'Y', 26, "Persea americana", 240, 45, 19,77, 4));

foodList.add(new FoodItem("09040","0900", "bananas, raw",

"Bananas, raw",

'Y', 36, "Musa X paradisiaca", 200, 25, 93, 3, 4));

foodList.add(new FoodItem("09063","0900","cherries",

"Cherries, sour, red, raw",

'Y',10,"Prunus cerasus", 77, 14, 88, 5, 7));

foodList.add(new FoodItem("12061","1200","almonds",

"Nuts, almonds",

'Y',0,"Prunus dulcis",54,163,14,73,13));

foodList.add(new FoodItem("12131","1200","macadamia nuts",

"Nuts, macadamia nuts, raw",

'N',69,"Macadamia integrifolia, M. tetraphylla",952,203,8,88,4));

foodList.add(new FoodItem("12155","1200","walnuts",

"Nuts, walnuts, english",

'Y',55,"Juglans regia",765, 185, 9, 83, 8));

foodList.add(new FoodItem("04581","0400","avocado oil",

"Vegetable oil, avocado",

'N',0,"",1927, 250, 0, 100, 2));

this.setList(foodList);

}

}

Hope this helps,

Chris

jetsons at 2007-7-7 12:17:14 > top of Java-index,Development Tools,Java Tools...
# 4

Thanks, Chris,

It definately helps. But I'm still having trouble getting a table component to see the columns from my object. I found out I had to close and open the project to see the new component, but even then, when I drag it onto my table component, the table component won't bind to it and won't tell me why it won't.

I'll keep playing with this to see if I can get it working. I'm obviously doing something wrong, somewhere...

There doesn't happen to be some interface that the FoodItem class implements, is there?

Thanks - I *do* appreciate your help!

RobertHouben at 2007-7-7 12:17:14 > top of Java-index,Development Tools,Java Tools...
# 5

I am not able to test out dragging and dropping right now but but I am not picturing what you are dragging onto the Table component.

See http://developers.sun.com/prodtech/javatools/jscreator/learning/tutorials/2/hib ernate.html#08.

When you right-click the Table component and choose Table Layout, are you not seeing your custom data provider in the Get Data From drop-down list?

If not, did you add the data provider property to the session bean as explained in steps 7-13 of http://developers.sun.com/prodtech/javatools/jscreator/learning/tutorials/2/hib ernate.html#object.

I do have a data providers tutorial on my priority list, but unfortunately, I have 3 other tutorials to do before I can get to it.

jetsons at 2007-7-7 12:17:14 > top of Java-index,Development Tools,Java Tools...
# 6

Hi Chris,

I figured out what was biting me. In order to bind this control intelligently, it needs to have at least one instance of data in it *at design time*, which wasn't happening of course, so I made my class look like below.

In short, I create a dummy record in the constructor so I can bind at design-time, then the first time I create a real record, I clear the list. I also have to make sure that I clear the list at runtime, so I added a setEmpty() method.

Thanks for your help - I'm off to the races now...

public class CUSTDataProvider extends ObjectListDataProvider

{

List custList = new ArrayList();

private boolean m_designModeData=true;

/** Creates a new instance of CUSTDataProvider */

public CUSTDataProvider()

{

addRow("foo", "bar");

setList(custList);

}

public void addRow(String id, String name)

{

if (m_designModeData)

{

custList.clear();

m_designModeData=false;

}

CUSTBean custItem = new CUSTBean();

custItem.setCUSTID(id);

custItem.setCustName(name);

custList.add(custItem);

}

public void setEmpty()

{

custList.clear();

}

}

RobertHouben at 2007-7-7 12:17:14 > top of Java-index,Development Tools,Java Tools...
# 7

Robert,

Although I do show that in the code (see below) I don't really emphasize that this is necessary for the design time experience. It is good feedback to know that this needs to be emphasized more.

// Put in dummy data for design time

tripsList.add(new Trip());

Glad you are finally able to get back to your task at hand.

Chris

jetsons at 2007-7-7 12:17:14 > top of Java-index,Development Tools,Java Tools...
# 8

Hi Chris,

I've been quite successful with building a DataProvider object to work with the Sun Java Studio Creator 2.1.

I wrap a custom java object of ours that accesses a 40-year-old non-relational database variant, and it in turn retrieves the data, then passes it into the list. In fact, I auto-generate the source-code for the provider and the underlying object it wraps in the list, so that the customer only needs to copy/paste the source files into his project and presto! it works!

I've figured out a mechanism that lets me create a dummy record for design-time, but also to override that when I'm using the bean as a property for my session bean, so I don't have to deal with the dummy record at run-time.

If you're interested, I would be glad to share my code. If you want it, send me an email at robert.houben@fusionware.net and I'll send you what i've got.

Thank you again for your help!

RobertHouben at 2007-7-7 12:17:14 > top of Java-index,Development Tools,Java Tools...
# 9
ChrisWhy hasn't Sun been able fix the ObjectListDataProvider? It's been broken for quite some time. The extends workaround results in unnecessary classes and code. It's also been the subject of countless forum messages because it doesn't work as documented.Dan
dkible at 2007-7-7 12:17:14 > top of Java-index,Development Tools,Java Tools...
# 10
I would be very interested in seeing what you have done. I would like to suggest that you share your code with the whole Sun Java Studio Creator community at http://wiki.java.net/bin/view/Javatools/SunJavaStudioCreator.Thanks,Chris
jetsons at 2007-7-7 12:17:14 > top of Java-index,Development Tools,Java Tools...
# 11
I didn't think pasting in comments and the text of 3 files would be very useful, but I wasn't aware that there was a place to upload sample code.I'll do that.
RobertHouben at 2007-7-7 12:17:14 > top of Java-index,Development Tools,Java Tools...
# 12

> Chris

>

> Why hasn't Sun been able fix the

> ObjectListDataProvider? It's been broken for quite

> some time. The extends workaround results in

> unnecessary classes and code. It's also been the

> subject of countless forum messages because it

> doesn't work as documented.

>

> Dan

Dan,

Let them know this is important to you:

http://bugs.sun.com/services/bugreport/studiobugreport.jsp?referrer=creator

jetsons at 2007-7-7 12:17:14 > top of Java-index,Development Tools,Java Tools...
# 13

Creator sure is a second class citizen when it comes to the bug database: If you go to http://bugs.sun.com/bugdatabase/index.jsp and try and search for creator bugs you'll have a really hard time finding any.

It appears Creator does not warrant an entry in the categories list.

Even if you search by keyword (I've tried "Creator" and "rave") you'll come up with a whole lot of entries filed against the one of the appservers.

I filed 3 RFEs 6 weeks ago. 2 were against Creator and one against the bug database. Got replies by email to say that both of the ones filed against Creator have been accepted to the database but no reply on the bug system.

====================================

Synopsis:Website -- Bug database not searchable

Description:

A DESCRIPTION OF THE REQUEST :

Main issue: Unable to search Sun's bug system for any Java Studio Creator Bugs or RFE's.

Sub issue: Creator support website has only a link to file a new bug/RFE.

JUSTIFICATION :

Allowing me to search for existing bugs and RFEs reduces your workload in dealing with them. Less duplicates. Less duplicated explainations.

EXPECTED VERSUS ACTUAL BEHAVIOR :

EXPECTED -

A drop down list that has the words "Java Studio Creator" in it on the Bug search page.

ACTUAL -

The opposite of the "Expected behaviour"

- BEGIN SOURCE -

Not applicable

- END SOURCE -

CUSTOMER SUBMITTED WORKAROUND :

None possible as far as I can see.

workaround:

yossarian at 2007-7-7 12:17:14 > top of Java-index,Development Tools,Java Tools...