ObjectListData Provider work around - Sample Project

Few Creator users left comments in my previous blog Work around for Object List Data Provider design time problem, stating that they tried the work around but it did not help. So I decided to write a sample test project.

You can download the ObjectListDataProviderTest.zip from here

The simplest way to use ObjectListDataProvider is to add ObjectListDataProvider from the palette and then set your java.util.ArrayList of objects using the property sheet. Unfortunately due to some bugs in Creator this doesn't work. That is why some work around is needed until the bug is fixed in the future release.

To test the downloaded ObjectListDataProvider test project, do the following
  • Open the project in Creator 2.
  • Clean and Build the application.
  • Close the project.
  • Reopen the project.

Note:The above steps are necessary because of some class loading problem in creator design time which will be fixed in future release.

  • Now drop a table component on to the designer
  • Bring up the table layout and select "nameListDataProvider" and close the dialog.

Now the table should display some sample data I added.

This is how I added the object list data provider to the application

  • Added a class called "Name" with two properties "first" and "last" (Constructor takes two arguments)
    (This is the object which holds the data)
  • Added another class called "NameListDataProvider" which extends ObjectListDataProvider.
    (The sample data is added in the constructor)
  • Added a property called "nameListDataProvider" (of type NameListDataProvider) to the Session Bean.

BTW, if you make any changes to the classes "Name" or "NameListDataProvider" you must compile close and reopen project.

Note: As it is pointed in the comment below, to make it work at runtime, add the following statement to the session bean init() method

nameListDataProvider = new NameListDataProvider();


It works, You are the man ! I will add this link to my Forum posting so people know how to do this. My problem most likely was not doing the clean build, close, and reopen. Nothing beats an example project file. At this point I am confident enough with the product to go ahead with using it on a significant project. There are a few bugs, but I have tried just about all the functionality at this point and the very few problems that exist have very reasonable work arounds. The project I have in mind is allowing users to create their own Database tables online with an easy to use interface, then render those tables for them on the web automatically. There will be some challenges, but I am pretty sure I can accomplish this in a reasonable amount of time using JSC. Thank you very much. Joe Paladin

Posted by Joe Paladin on February 21, 2006 at 12:32 AM PST #

Thanks for this article. I tried the sample project but I still don't see the sample data in the Table when I run it. Am I doing it correctly?

Posted by Jayaraj on February 21, 2006 at 01:58 AM PST #

After following your instructions, nameListDataProvider does not appear in the Outline nor the the table layout dialog :-(

Posted by Dan on March 02, 2006 at 07:21 AM PST #

Disregard my last comment. I got ahead of myself and forgot to close and reopen the project. Btw, in order to get the data to show in the browser, I had to instantiate the nameListDataProvider on the sessionBean1 init() nameListDataProvider = new NameListDataProvider(); Thanks for the help.

Posted by Dan on March 02, 2006 at 07:35 AM PST #

Thanks for this tip!

Posted by Frederic Bergeron on March 02, 2006 at 09:30 AM PST #

To make it work for runtime, add this statement to the session bean init() method nameListDataProvider = new NameListDataProvider();

Posted by Diva on March 10, 2006 at 02:31 AM PST #

Thanks for this useful workaround... (no doubt a future release will fix this)
BTW, there is also an important feedback on POJOs field mapping I'd like to submit you :

Not a big surprise that several objects (I may bind to a Table) use composition !
Unfortunately, these "sub-objects" just appear as a whole in the available fields :-(
It would be great if introspection of the "target" class was a bit recursive, then producing enumeration of compound fields like [address.street] for instance. It seems that this would fairly match with the current design as it's "quite" what is done for direct database column binding.
While navigating in the r/o source code from the IDE, I found an introspect() method in the ObjectFieldKeySupport class. I guess, it's where the things take place...

Nevertheless, maybe a workaround still exists by dealing with FieldKeys[] in the OLDP subclass ?

Posted by Eric Camps on March 28, 2006 at 12:28 AM PST #

Thanks for a very nice sample project. I have tried it and it worked. But when I try to do the same thing with my existing project, the provider I have created does not show up on the table layout provider dropdown. I have refactored my bean classes (Session, Request and Application) into a different package and had removed the bean links on the project tree (the beans can only be seen on the source packages). Maybe that's causing the problem. I have tried creating a new project and followed the steps you have given and it works. But when I try to refactor the bean classes into a different package, it does not work. Any ideas why? I think its a creator bug.

Posted by sirkware on March 29, 2006 at 04:04 PM PST #

hellp winston. your weblog has been really helpfull to me i must confess. Iam having a little problem and i think that you might be of help. I am trying to run a dynamic search query where the user selects a search criteria and supllies the search value i dynamically change the command of the rowset in this case and it refreshes the dataprovider but my problem is after the dataprovider refreshes i want to get the selected row ,but it does not return the selected row instead i get a different row each time i make a search ,please you have any idea .

Posted by Iyenemi I Tyger on April 05, 2006 at 07:53 PM PDT #

hello everyone, before making my question I have to say this is a very nice sample and it works perfectly, but I have little a question, there is a way to assign de Array of Objects at runtime, since bean is empy and filled from database while app is running thanks in advanced

Posted by jesus on April 25, 2006 at 05:12 PM PDT #

Many thanks Prakash. We all really want studio creator to succeed and your efforts go along way to achieving that goal.

Posted by James on May 22, 2006 at 05:35 AM PDT #

I've discovered a useful tidbit: in order for JSC to change a GUI table to match the resources of an object when you drop the object's list data provider onto the table, the names of the object class and the object list data provider class must be coordinated. In other words, if the class that represents one row in the table is Foo, then the list provider class must be named FooListDataProvider. In this example they are coordinated. But if, for example, the underlying object had been called NameBean, it wouldn't have worked. However, as best I can tell, once you have your GUI table created, you're free to rename your classes.

Posted by Topher Eliot on June 12, 2006 at 04:13 AM PDT #

I got same problem as sirkware. I could not make my existing project refactored to bind to objectListDataProvider. your example works fine. Prakash, Do you know the cause? Thanks.

Posted by Zheng on June 23, 2006 at 09:42 AM PDT #

Hey Winston, thanks for your solution. What I come here to question is if this particular solution will only un-bug the design time displaying or will it make tables refresh their list with modified fields by user, for example, too??

Posted by Gabriel Galvão on August 03, 2006 at 05:51 AM PDT #

Hello Winston, Thanks for the sample. I tried it and could see the arraylist data in table. After this i tried on the my actual project. But there, the Arraylist is very dynamic, the whole array list is created after parsing an XML file which can contain any number of tags. In this case I can see the xmlDataProvider in the dataprovider dropdown but since the arraylist doesnt contain anything initially, i can not use it. Could you please help, how can i load an XML file in a UI Table. Thanks for your help. -Bhajan

Posted by Bhajan on August 19, 2006 at 03:09 PM PDT #

Hello Winston, the Object List Data Provider sample worked but I had some problems in implement it in my app (I use the Java Creator in my Job), I can't bind the dataProvider to a table if don't initialize it with some data... just as you did in your example... take a look please... your help is most welcome!! public class NameListDataProvider extends ObjectListDataProvider{ private ArrayList nameList = new ArrayList(); public NameListDataProvider() { } }

Posted by Daniel mopont on December 10, 2006 at 09:46 PM PST #

If you don't want to initialize your ObjectListDataProvider, then you have to set the Object Type. Try overriding the property ObjectType of your data provider. Ex. public Class getObjectType(){ return myPackage.myObject.class; }

Posted by Winston Prakash on December 11, 2006 at 12:52 PM PST #

I could replicate your example of table binding by ObjectListDataProvider which shows data in a txt file. I run a function by button click which changes data in txt file. I tried using the code in session bean in request or application bean with no success. I want the changed data in txt file to show in Table.Please help. dr.am mohan rao

Posted by am mohan rao on January 06, 2007 at 03:21 PM PST #

Is it possible to have multiple OLDPs within a single application? For example, I have one table I want to populate with a list of object type A, and on a page change I want to populate another table with a list of object type B. I try to switch the lists (using setList function) on page change, which it does correctly, however it has problems rendering the table (it give me an error in the portlet). Any suggestions?

Posted by sean downey on January 15, 2007 at 10:24 AM PST #

I can't get this to work either. I downloaded the zip, and it would not build. So i reviewed the code and saw how the data provider worked with the POJO, and duplicated it. I followed some of the build/clean/closeproject tips from this article: http://blogs.sun.com/divas/entry/using_the_object_array_data. This is where it got strange. In the design view, my table showed the table with first and last, and three rows of names. But when I ran the app, the web page that was rendered said "No items found." This seems odd: data available in design view, but not at run time? thx,

Posted by Kevin on March 16, 2007 at 04:08 AM PDT #

I get it now... when you declare your class, you have to trick the designer by providing some kind of object for the list. Whatever type of object that is, shows up in the designer as columns. What surprised me was that the designer executed the sql query to fetch actual results in design view. I had a bug that prevented me from seeing the data in deployed view. Nice feature, but confusing because of a series of events to me.. thx

Posted by Kevin on March 19, 2007 at 12:37 AM PDT #

Kevin, I'm surprise to see that you have mentioned "designer executed the sql query ..". This is not correct. Did you see any actual SQL query related stack trace. The message in the designer is mererly informative. It just says, it could be because of SQL query failure, but not necessary. BTW, we are looking at the possibility to use "Generics" to get the Object type.

Posted by Winston Prakash on March 19, 2007 at 12:55 AM PDT #

Hi, i use table binded with list data provider, in table if i change checkbox or text field value and i want to retrieve new value it don't work. I use this code to d this: try{ this.getSessionBean1().getZipEntryListDataProvider().cursorFirst(); do { String dest = (String)this.getSessionBean1().getZipEntryListDataProvider().getValue("destinat ion"); System.out.println(dest); info(dest); } while (this.getSessionBean1().getZipEntryListDataProvider().cursorNext()); return null; } catch(Exception e){ info(e.getMessage()); return(null); } if i bind table with a cachedrowset dataprovider this code work fine and i have the new values entred by user how to do this with ListDataProvider Thanks

Posted by walid on April 05, 2007 at 01:32 AM PDT #


Posted by guest on June 26, 2007 at 10:19 PM PDT #

Winston, I'm trying to make a hyperlink column but the action never was trigger it. I test with a button and other objects but anything works. There are some problems with ListDataProvider and actions?
When a I follow the simple drop "sql table" inside the "design table", I get success, but with a List (better implementation to my case) is like the actions doesn't exist.
I'm trying by 4 days includes this without any clear explanation.

Posted by Frank on July 25, 2007 at 11:11 AM PDT #

I found the problem, was a init mistake. The dataprovider need to exist before the Phase that process the actions. So, the code was moved from prerender to init.
Sometimes I forgot the basic and important concepts.
See you.

Posted by Frank on July 26, 2007 at 02:57 AM PDT #

Hi winston,I am deploying creator table in weblogic 8.1.The table component is bound to objectlist dataprovider.The table is rendered without any data on the screen.The dataprovider has data at the time of rendering but on screen no data.I tried having dataprovider as a property of both the page as well as part of sessionbean.To add to this the init method of sessionbean is never called.I have tried all the tricks provided by you.Can u pls kindly help in this regard.It is very urgent.

Posted by Vijay on August 05, 2007 at 08:50 PM PDT #

hi winston. thanks a lot for the code. but one thing how do i get data from the method that gives a list of objects that is given by another project for ex J2ee ejb project that uses jpa

Posted by surya chandra on October 25, 2007 at 12:21 AM PDT #

Hi Winston. Thank you for the working example which was really useful. I was wondering as to whether conceptually this code should be added to the session bean or application bean? I was also wondering whether it is possible to create a table at run-time with variable number of columns depending on what the query demands. Some queries require only 2 comlumns to be displayed while others may require 6 columns. Is this possible?

Posted by Ranjan on November 12, 2007 at 06:02 PM PST #

Rajan, that depends on how your data is accessed. If you want all the users to have the same set of data then place it in the Application bean, other wise at Session Bean for each user to get their own set of data.

I have two articles explaining how to create dynamic tables at http://www.winstonprakash.com/articles/articles.html

Posted by Winston Prakash on November 12, 2007 at 10:37 PM PST #

Hi, Winston. I'd like to know how to display search result in the table component. You have to put the search input then click search button. Can you tell me the concept to do that? thank you in advance.

Posted by wowerng on January 07, 2008 at 02:55 PM PST #

Hi winston.
I need a small help.
I need to use Maps instead of List for getting the data into a table form an excel sheet using jsf.I am using netbeans 6.0 ide.can u please help me.
Awaiting for your response.
Thanks in advance.

Posted by Anvesh on April 10, 2008 at 09:15 PM PDT #

I don't think there is proper documentation or tutorial to explain how to use maps. Probably you should extract out the values of the map as list or array and then show it the table.

Posted by Winston Prakash on April 11, 2008 at 12:41 AM PDT #

Post a Comment:
  • HTML Syntax: NOT allowed

« July 2016