Put some debug (System.out.println or (SOP in short))statements in your managed bean method and then in your console you should be able to see at what phase are your methods being called.
FacesContext context = FacesContext.getCurrentInstance();
boolean renderResponse = context.getRenderResponse();
Perhaps my problem could be solved in a cleaner way, so allow me to describe it:
I have an ordinary web page: the top half lets you insert, edit or delete records and the bottom half has a MyFace's DataTable that shows the results of selecting certain summary information from the database. The bean backing this table is request-scoped and its data method used to go to the database the first time it was called:
The trouble with this is that when you submit from this page, before the insert/update/delete action is done, the view is restored which means that my getResults method is called! So my results are a snapshot of the db's state *before* the database action. My solution was to make this method even lazier -- don't try to find any data until the response phase:
This works but I wish it were cleaner. I'm not sure what I want, but since my table has no input fields in it, I wish the backing bean was not created until the response phase. Hmmm.... could this be because my results table is inside the HTML FORM tags? I'll have to play with this a bit more...
[ May 04, 2006: Message edited by: Jeff Albertson ]
Tie the action listener event of the top half-page in order to initialize an instance variable that can be checked in your getResults()method. Since action listeners happen at phase 5, you should be pretty much lazily loaded.
Please let us know if this worked for you.
Sample code is as below.
[ May 04, 2006: Message edited by: g madhava ]
(BTW, moving this table out of the scope of the FORM tags didn't change anything.)
I was just giving an alternate solution that doesn't deal with the FacesContext. and is much cleaner.(atleast in my opinion).
I didn't get your point overhere,
table needs to be rendered whenever this page is displayed, not just after carrying out a insert/save/delete.
The table will always be rendered, but the data will be loaded pretty lazily. I thought that was the requirement.
May be I was missing something ?
For example, there are lots of other pages that are linked to this page, and I don't know if its a good idea to require those pages to know about setting that flag. I'd like my backing bean to look after itself...
Yes, if all the pages need this particular lazy loading of the data, then you should be fine with the above solution. But in case if you want it to be customized for each different page, then you might need to have some more code for conditional checking using the viewId of the request page.