File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSF and the fly likes JSF row selection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "JSF row selection" Watch "JSF row selection" New topic
Author

JSF row selection

Mohammad Jaber
Ranch Hand

Joined: Apr 10, 2006
Posts: 46
Hi all,

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.

Thanks
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16160
    
  21

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
Mohammad Jaber
Ranch Hand

Joined: Apr 10, 2006
Posts: 46
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 !!!
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16160
    
  21

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSF row selection