Interesting approach, I would have implemented a full model to do it, like I recommended.
But yours looks much more compact.
I never thought of applying a delegate to an existing model.

Just a minor question, do you have callbacks into the setRowIndex method as well, because I just wonder if you load the entire collection at once
or the objects only by demand.

The reason why I am asking this is, that you might bet a much better
mem footprint if you apply the rowIndex callbacks as well and use an iterator, because to my knowledge only the page data is requested normally, not the entire collection, if you enable the datatable paging.


Werner


Enrique Medina wrote:
Hi again,

I finally solved my problem ;-)

As I told you, I have extended the ListDataModel class to provide it
with a callback mechanism to be able to reattach any object to the
current Hibernate session.

Let me show you the code:

// Provide the callback within the constructor.
public LazyListDataModel(List list, DataModelCallback dataModelCallback)
{
        super(list);

        this.dataModelCallback = dataModelCallback;
}

// Overwritten method to call the provided callback method.
public Object getRowData()
{
        // Get the object...
        Object object = super.getRowData();

        // ...and call the callback method before returning the object.
        if (this.dataModelCallback != null)
        {
                this.dataModelCallback.execute(object);
        }

        return object ;
}

Then, the DataModelCallback is a simple interface:

public interface DataModelCallback
{
        public abstract void execute(Object object);
}

And finally, I simply use this special lazy implementation of the
DataModel in my JSF bean:

this.workingDataModel = new LazyListDataModel(this.searchData(), new
DataModelCallback()
{
        public void execute()
        {
                // Call Hibernate's lock stuff...
        }
}


Reply via email to