• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Empty web page data table

 
Michael Brooks
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 808
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18304
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic