Hi Werner, As we've been discussing, I'm only interested in getting a reference to the object being processed by each row in the DataTable, so IMHO the perfect point to get it is in the getRowData method.
Currently, I'm loading the entire collection at once. This is an interesting area of discussion about pagination. After some investigation and comments from other developers, I ended up by just retrieving an exact number of records, e.g. the first 1000, because it does makes not make so much sense to implement such a complicated DataModel, and it would be as simple as asking the users to refine their searching criteria. So I simply use the Criteria API with setMaxResults(int max) to limit the number of results. 2005/6/21, Werner Punz <[EMAIL PROTECTED]>: > 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... > > } > > } > > > >