This week's book giveaway is in the OCAJP forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide 1Z0-808 and have Jeanne Boyarsky & Scott Selikoff on-line! See this thread for details.
I am writing an search application that allows users to query a rather large table via a fill-in-the-blank type form. The hardest part was dealing with the fact that they can also configure and use different select statements which alters the number of fields returned. I am using the MyFaces implementation and it works. Sort of. The weird thing is that after boot, the first search doesn't display any records, though tracing through the code shows records returned and converted to a List. Subequent searches work immediately. At least I hope they are and not showing old data. Here's the quandry.
The SearchVerifyBean takes the values from the form and if valid, creates a WHERE clause (and optional ORDER BY clause), loads the selected SELECT clause and writes them all to a work table. It then loads the TransactionSearchBean and sets a "do search" flag to true, and returns success so that JSF then navigates to the searchResults.jsp page. That page references the TransactionSearchBean - which hasn't done the search yet.
Since the field list is dynamic, the searchResults.jsp page is fairly empty and I create the <DataScroller> and <DataTable> objects in code, built on the fly based on the fields from the result set. The thing I can't grasp is how to make the bean do the actual search when the page is loaded, NOT when it needs to get a page worth of data to display.
I have a UIPanel object in my class BINDed to the page construct where the data scroller and table reside. I altered my code thusly:
the doSearch() method calls the stored procedure to load the three clauses and runs dynamic SQL to return what the user wants. It then extracts the meta data to construct the <DataTable> object and everything is then displayed.
Only it isn't quite right. As I said, the first search always returns "no results" despite the fact that there is data ready to be displayed.
I know this is a timing issue and am still a bit fuzzy about the JSF phases.
Has anyone done anything remotely similar to this?
Is there a way to setup an event listener that will be called when the page is initially loaded/navigated to? That way the searching/ loading/ construction is done before the JSF phase to actually display the data is called?