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 calli开发者_StackOverflowng a javascript function for onLoad of tag. The method is called only after the slow db query executes.
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.
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
).
精彩评论