Not as far as I know. And this is a major problem, in my book. Also, you need to keep the data across HTTP request, because the darn thing bases it's interaction logic on the position in the list.

A simple click, e.g., to navigate to 1 detail, will require the entire datamodel to be iterated on that next request, which requires either a) to get all records again from the DB, although you only really need the one to show the detail of, or b) to keep all records in in session scope for that next request. The request carries information that says "the user clicked on row n", not "the user clicked on the record with PK foo".

In case a), you need to make absolutely sure that the newly retrieved datamodel has the exact same entries, in exactly the same order. Damn impossible if, e.g., records were removed or added in-between requests, and damn difficult if you're not working directly with SQL, but, e.g., with Hibernate with a Set association (no order).

In case b), you're keeping all the records in session scope indefinitely (the user might never come back). If you're showing a list with a lot of entries (think 100 or 1000; and this also applies if you do paging), all these records are all the time in RAM, for each user that has a session on your server. Damn ludicrous. O yeah, you can also store the state in the client: you will then have a 5 MB base-64'ed string in your HTML and POSTs page going back and forward.

Of course, while you're doing edit-in-grid, you need to iterate over the data model for apply request values, conversion, validation, apply model values, …. But not for a simple navigation. And I bet you're not doing edit-in-grid for all 100 records at the same time. ;-).

In the short run, where using a hidden field outside of the table, and the navigation commandButton in each row has a little JavaScript that sets the PK of the record of that row in that hidden field, and submits it. Still, the iteration over the datamodel happens, but if we take care that the datatable does not contain any input fields, the datamodel can stay lazy. So, we implemented a lazy datamodel that only goes to the DB if the instances are really needed.

The fundamental solution would be to create a new component that uses the PK of objects as row-identification, to know where the user clicked.

In conclusion: dataTable is a dragon. It can be used for small tables, think of a shopping cart, with 4 entries, that take little RAM. Using it for master-detail of a large result sets from a database (or large collections via Hibernate) will get you into trouble.






On 6 Aug 2005, at 11:26, Boris Kovalenko wrote:

Hello!

As I understand, MyFaces (and core JSF too) evaluates value getter for DataTable twice (or three times if preserveDataModel == true). If we are getting static data there is no problems, but if we'are populating data from SQL we get a big problems (as query are running twice). For the time present I found no another solution as:

public Collection getDatatableValue() {
if(array != null)
return array;
array = new ArrayList();
.... bla bla populating array
return array;
}

Same may be done with DataModel. Want to know what other people doing in this sutiations? May be there is another solution?

With respect,
Boris


<x-tad-smaller>Met vriendelijke groeten,

Jan Dockx
</x-tad-smaller><x-tad-smaller>
PeopleWare NV - Head Office</x-tad-smaller>
<x-tad-smaller>
Cdt.Weynsstraat 85
B-2660 Hoboken
Tel: +32 3 448.33.38
Fax: +32 3 448.32.66 </x-tad-smaller>
<x-tad-bigger>
</x-tad-bigger>
<x-tad-smaller>
PeopleWare NV - Branch Office Geel</x-tad-smaller>
<x-tad-smaller>
Kleinhoefstraat 5
B-2440 Geel
Tel: +32 14 57.00.90
Fax: +32 14 58.13.25</x-tad-smaller>
<x-tad-bigger>
</x-tad-bigger>
<x-tad-smaller>
http://www.peopleware.be/
</x-tad-smaller><x-tad-smaller>http://www.mobileware.be/</x-tad-smaller>

Attachment: smime.p7s
Description: S/MIME cryptographic signature

Reply via email to