You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Boris Kovalenko <bo...@tagnet.ru> on 2005/08/06 11:26:49 UTC

DataTable and SQL best practices

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

Re: DataTable and SQL best practices

Posted by Boris Kovalenko <bo...@tagnet.ru>.
Hello!

> 
> btw: your code wont work if user enter on same page second time
> obviously if(array != null) is true so no "bla bla" is performed
Why? My experience shows that it works. It want work if I will use 
session scope beans, but I use request scope. But I agree that getter 
should be getter and nothing more.
> 
> Sławek Sobótka
> 
>> 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
>>
> 
> 
> 
Regards,
	Boris

Re: DataTable and SQL best practices

Posted by Slawek <ss...@o2.pl>.
just dont put data fetching in getter

i assume that user must click link or button to see your page with 
datatable.
so, u can perform data fetching in action binded to that buttotn (or link) 
- that action returns string that is "maped" to your view.

your action does ".... bla bla populating array" and set bean's datamodel

getter ONLY gets that model


btw: your code wont work if user enter on same page second time
obviously if(array != null) is true so no "bla bla" is performed

Sławek Sobótka

> 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
>



Re: DataTable and SQL best practices

Posted by Boris Kovalenko <bo...@tagnet.ru>.
Hello!

> I don't get your way completely, so I wont comment on it now. About the 
> 1 minute though: watch out for a browser timeout (usually 1 minute). 
> You're going to have to feed something over the TCP/IP connection during 
> that minute, to avoid all sorts of timeouts. No idea how to do that with 
> JSF though.
Hmm... AFAIK many system (FreeBSD, Linux fo example) has TCP keepalive 
function implemented as many java containers (Resin for example) has 
HTTP ping function implemented.

With respect,
	Boris

Re: DataTable and SQL best practices

Posted by "ir. ing. Jan Dockx" <ja...@mac.com>.
On 6 Aug 2005, at 13:12, Boris Kovalenko wrote:

> Hello!
>
> 	Ok, I undestand You, thanks. Yes, I found that use <f:param> for 
> commandLink is more

Yes, but that only works with commandLinks, and not with 
commandButtons. Rather inconsistent, but hey …

> pretty then use DataModel.getRow() (which has bug in multiwindow 
> enviroment which should be fixed in 1.2 spec, but how quick will 
> that?). I talked about big reports that spend much time to get results 
> from database (up to 1 minute). So, in this sutiation the better way 
> is the one I use one. Isn't? (If we are talking about pure JSF)

I don't get your way completely, so I wont comment on it now. About the 
1 minute though: watch out for a browser timeout (usually 1 minute). 
You're going to have to feed something over the TCP/IP connection 
during that minute, to avoid all sorts of timeouts. No idea how to do 
that with JSF though.

>
>> 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.
>
> With respect,
> 	Boris
>
>
Met vriendelijke groeten,

Jan Dockx

PeopleWare NV - Head Office
Cdt.Weynsstraat 85
B-2660 Hoboken
Tel: +32 3 448.33.38
Fax: +32 3 448.32.66

PeopleWare NV - Branch Office Geel
Kleinhoefstraat 5
B-2440 Geel
Tel: +32 14 57.00.90
Fax: +32 14 58.13.25

http://www.peopleware.be/
http://www.mobileware.be/

Re: DataTable and SQL best practices

Posted by Boris Kovalenko <bo...@tagnet.ru>.
Hello!

	Ok, I undestand You, thanks. Yes, I found that use <f:param> for 
commandLink is more pretty then use DataModel.getRow() (which has bug in 
multiwindow enviroment which should be fixed in 1.2 spec, but how quick 
will that?). I talked about big reports that spend much time to get 
results from database (up to 1 minute). So, in this sutiation the better 
way is the one I use one. Isn't? (If we are talking about pure JSF)

> 
> 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.
> 

With respect,
	Boris

Re: DataTable and SQL best practices

Posted by "ir. ing. Jan Dockx" <ja...@mac.com>.
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
>
>
Met vriendelijke groeten,

Jan Dockx

PeopleWare NV - Head Office
Cdt.Weynsstraat 85
B-2660 Hoboken
Tel: +32 3 448.33.38
Fax: +32 3 448.32.66

PeopleWare NV - Branch Office Geel
Kleinhoefstraat 5
B-2440 Geel
Tel: +32 14 57.00.90
Fax: +32 14 58.13.25

http://www.peopleware.be/
http://www.mobileware.be/