if i need to build my own datatable selection mechanism, i mean i want to use the <h:dataTable> along with some mechanism to add the row selection cabapilities, how is the best way to do that, i tried adding a checkbox or radio as a column, but my problem is that when post back to the server, the datasource of that table will be invoked again which could get more or less records than the originally displayed ones and select the wrong record based on order.
so i think its better to get the datatable content from the request or so, any suggestions.
Actually, the datasource will only be contacted if your dataModel object is tied directly to it.
There are a number of alternatives. If the amount of data is small, just cache it and have the dataModel refer to the cached copy. This is fairly easy to do if you're using an ORM such as Hibernate or EJB.
A variation of that is to cache just the record keys. Takes less memory and you can set things up so that only the referenced items are fetched from the datasource. Less overhead, plus you get exactly the same items in the same order as the set of keys referenced.
Sometimes the only way things ever got fixed is because people became uncomfortable.
caching is something i thought about, but my question is how to utilize and use the request information during the post back, how does most of the extended JSF library that supports out of the box row selection works, do they cache either the record or thier keys !!!
Mohammad Jaber wrote:caching is something i thought about, but my question is how to utilize and use the request information during the post back, how does most of the extended JSF library that supports out of the box row selection works, do they cache either the record or thier keys !!!
They don't cache either one. JSF's dataTable references a bean property that implements the JSF DataModel interface. It has no requirement that the DataModel be connected in any way, shape or form to a database. About all it's for is to provide a mechanism to serve up per-row data and a cursor to step through the row. You could synthesize the row data from thin air and it wouldn't care.
Although some of the DataModel implementations do bind directly to a datasource, most don't. In fact, I've never used the JDBC datamodel myself.
Let's go to the waterfront with this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss