I have a JSF web application which includes a bean which
navigates to a new page by passing the web page as a return value.
The page loads as expected. However, the page displays an empty
table. In the facelet definition of the table
is value=cdibean.getAllXXX() which populates the table.
I added log messages in this method. I was assuming that since
I put a @PostConstruct annotation on the method, when the web page
was loading the method would be called prior to presentation;
however, the web page loads and the getAllXXX method is never
executed. No log messages in log. What am I missing?
We work best when you can give examples of the core problem areas. Too little information and we can only make guesses. Too much and we often lose the forest in the trees. And, of course, knowing what to show us can be tricky, since if you knew where the problem is, you probably wouldn't have the problem!
One thing that set off an alarm for me, however was this:
In the facelet definition of the table is value=cdibean.getAllXXX() which populates the table.
To me that sounds like you are attempting to put logic in the View definition. And, as I continually warn people, you shouldn't do that. Put the logic in the backing bean.
@PostConstruct is not actually JSF. It's part of a more general standard for automated bean instantiation and initialization. In particular, it does not mean "run this when the page is displayed". The PostConstruct is run once and only once when a bean instance is constructed, so the closest thing to "when the page is displayed" would be for request-scope backing beans, and you cannot do datatable models in request scope because the continual destruction and reconstruction of the containing bean also destroys the context information in the DataModel. Besides, since JSF is heavy into postbacks, the page may be displayed many times, not just once.
Usually the cleanest way in JSF to initialize a backing bean is to do so before navigating to the page that uses the bean. Inject the new page's backing bean into the originating page's backing bean, then invoke an initialization method on the new page's bean.
An IDE is no substitute for an Intelligent Developer.