This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes JSF and the fly likes Empty web page data table Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Empty web page data table" Watch "Empty web page data table" New topic
Author

Empty web page data table

Michael Brooks
Greenhorn

Joined: May 11, 2011
Posts: 11
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?
dennis deems
Ranch Hand

Joined: Mar 12, 2011
Posts: 808
To populate the table you just want a regular getter that returns the collection.

@PostConstruct is for initialization of your bean. In particular, note these requirements from the JavaDoc:
Only one method can be annotated with this annotation.
The return type of the method MUST be void.


Can you post the relevant portions of the html and java source?
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16019
    
  20

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Empty web page data table