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
When the button is clicked and the page is submitted, the button event listener does the following
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.