Testing if Object List Data Provider is transactional?

A question came up in the forum about ObjectListDataProvider, asking if ObjectListDataProvider is transactional?.

According to the Java Doc of ObjectListDataProvider:

This class implements TransactionalDataProvider semantics, meaning that all updates to existing fields, as well as inserted and deleted rows, are cached until commitChanges() is called. Once that call is made, any RowKey you have retrieved from this instance is invalid, and must be reacquired. 

So, I decided to test this and created a test project which can be downloaded from here.

This project is an extension of the sample project I put in my previous blog http://blogs.sun.com/roller/page/winston?entry=objectlistdp_sample_project. So the work around steps explained in that blog must be followed.

In this project, I additionally added two components and modified the Table component as follows

  • A Button component to submit the page.
  • A MessageGroup component to display data from the ObjectListDataProvider.
  • The component type of the last name column has been changed to TextField.

When the button is clicked and the page is submitted, the button event listener does the following

  • Adds a new Name object to the ObjectListDataProvider
  • Commits the changes to the ObjectListDataProvider.
  • Retrieves the data from the ObjectListDataProvider and adds it to the context as information message, which will be displayed by the MessageGroup when the page gets rendered in the browser. 

The code in the button action handler looks like this.

      
   public String button1_action() {
        Name addedName = new Name("Gabriel", "Galvao");
        this.getSessionBean1().getNameListDataProvider().appendRow(addedName);
        this.getSessionBean1().getNameListDataProvider().commitChanges();
        List myList = getSessionBean1().getNameListDataProvider().getList();
        for(int i=0; i< myList.size(); i++){
            info("Full Name: " + ((Name)myList.get(i)).getFirst() + "  " + ((Name)myList.get(i)).getLast());
        }
        return null;
    }
    

Following images show the results before and after the page is submitted. Before submitting the page, I changed the last name of Jeff Hudson to Jeff Jackson which is correctly displayed in the MessageGroup along with the added name Gabriel Galvao after the page is submitted. So, as we see through this sample ObjectListDataProvider is indeed transactional.

Comments:

Winston! Thank you very much for that sample project. I was doing things wrong. Not using appendRow for inserting on table, directly inserting on my ArrayList, which is really a dumb thing to do architecture-wise. In the end it was all a big fault of mine. I don't know now if I get ashamed of asking such question. But thank you very much for clearing it up. Regards, Gabriel Galv√£o

Posted by Gabriel Galvão on August 05, 2006 at 12:10 PM PDT #

Hi Gabriel, some time we miss something and it happened to me several times, so you are not alone :). Getting things clarified is a good thing not a bad thing.

Posted by Winston Prakash on August 06, 2006 at 01:50 AM PDT #

Hi! I test your example "How to create single selectable row Table component", but, when execute it, the message group control show : "Error setting 'selected' in bean of type page1: java.lang.ClassCastException: java.math.BigDecimal".

Posted by Connall on August 18, 2006 at 07:58 AM PDT #

thanks for this. I had Text Fields in my table that did not seem to be holding their new values. ie. I'd edit the field, then click 'Update' and they values would not change! Turns out I had to to call 'commitChanges' on the ObjectListDataProvider in my update_action() method. I'd spent half a day trying to solve this!!

Posted by Matt on November 28, 2006 at 09:35 AM PST #

I have noticed that the commitChanges does not work on a textarea (or maybe in a textfield) that is disabled? But when I try to reload the page, the value is saved since the table is being populated from a given source. To fix this, I just made a workaround to fix this problem. Upon reloading of the page after commitChanges, I just reload the data provider, clear everything then repopulate. I'm not sure if this is known bug of textarea and maybe a textfield too. Hope you can shed more light on this one. Thanks.

Posted by eebora on January 09, 2007 at 04:53 PM PST #

On Adding a Value Change event to the text Field in this example, the values changed in the text fields across the rows are not retained on the screen. Is there some thing I am missing to get all the retained values The text field has a Auto submit to True Austin

Posted by Austin Fernandes on April 23, 2007 at 09:03 AM PDT #

The problem with objectListDataprovider in studio creator still persist in netbean 6.0?
I try to craate a test engine and retrieve question directly from database. The Cursornext method did not work. I created objects of my questions as suggested by you, and make that class a field in my sessionBean. When I try to bind that objectListDataProvider in my page, I cannot locate the object in the list property of my objectListDataProvider that I drop on the page. This was a problem in studio creator. I guess it must have been solved in netbean 6.0. Please, how can i move forward, this is delaying my work

Posted by Ogunfunminiyi Frankfurt on March 27, 2008 at 12:56 AM PDT #

The problem with objectListDataprovider in studio creator still persist in netbean 6.0?
I try to craate a test engine and retrieve question directly from database. The Cursornext method did not work. I created objects of my questions as suggested by you, and make that class a field in my sessionBean. When I try to bind that objectListDataProvider in my page, I cannot locate the object in the list property of my objectListDataProvider that I drop on the page. This was a problem in studio creator. I guess it must have been solved in netbean 6.0. Please, how can i move forward, this is delaying my work

Posted by Ogunfunminiyi Frankfurt on March 27, 2008 at 12:57 AM PDT #

Hi Ogunfunminiyi, did you try as I mentioned in my blog http://blogs.sun.com/winston/entry/nb6_table_binding_enhancement

Posted by guest on April 01, 2008 at 12:52 AM PDT #

Post a Comment:
  • HTML Syntax: NOT allowed
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