views:

56

answers:

2

I have a jsf page having a request scope bean. A slow database query is fired in the constructor of the request scope bean. Then, the results of the query are shown in a jsf data table on the web page.

How do I display a wait message until the database query completes?

I tried calling a javascript function for onLoad of tag. The method is called only after the slow db query executes.

+2  A: 

The slow database query is happening on the server, long before the constructed page ever makes it out to the browser. The only way to do what you want is to arrange for the browser to display the "Wait" message before you initiate the HTTP request that results in your JSF page being run.

Probably the best way to spend your time on this, however, is to fix the query.

Pointy
Its a huge query which I cannot change. Well, I can use your approach but I guess I will have to use a session scoped bean. Am I wrong?
outvik
Talk to DBA's. You should really consider DB-level pagination. Right now it sounds much like that you're duplicating entire DB table with thousands of records into Java's memory for every single enduser. This might blow up your app sooner or later when heavily used/visited.
BalusC
BalusC, You are right. DB pagination must be more efficient. I am going through your blog for examples.
outvik
+1  A: 

You must load the "wait page" first and then, in the onLoad of that page, load the one which does the DB query. If the query is fast, the user won't see much flickering because modern browsers (= anything but IE6).

Alternatively, you can load the result in a hidden iframe and show a "please wait" in the page. When the code in the iframe has loaded, you can make it visible by accessing the parent document with parent:

parent.getElementById('frame').styles.display = '';
parent.getElementById('wait').styles.display = 'none';

(put this in the onLoad of the JSP which is inside the iframe).

Aaron Digulla