aspose file tools
The moose likes JSF and the fly likes Populating Datatable from Database Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » JSF
Reply Bookmark "Populating Datatable from Database" Watch "Populating Datatable from Database" New topic
Author

Populating Datatable from Database

Mike Boota
Ranch Hand

Joined: Jul 18, 2002
Posts: 82
Hi,

I am still learning JSF and need some help. I have a Page with one datatable and one command button to create a new record that takes to a new page where a user creates a record and the out come routes back to the dataable page. Whenever a user comes to a page datatable is populated with values from the database. Here is what I have done in the backing bean constructor I am calling a method that gets the data from database and populates the list that is the source for the datatable. Now if there is no data in the database I only see headers. Now if an error occurs while connecting to the database I want to show an error on the same page and below the empty datatable with command button, how do I handle this.

Next when a user clicks on a command button I have an associated action listener in the backing bean but some how it always executes the constructor first and then the action listener method and if the database fails it never executes the action listener. How do i handle this.

Can someone please help me what is the best way to do this. As when a user comes to page wants the datatable automatically populated. Is doing this in backing bean constructor the only way. Any help is appreciated.

Thanks


MB<br />Sun Certified Programmer for Java2 Platform
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 12513

Just define a String property in your backing bean that returns a status/error message and set up an output text element in your JSF page to display it. At its simplest, you can just return an empty string if there's no error, or if you prefer you can add additional properties to control whether the output text item is displayed at all if empty, select a highlighting style based on error severity, etc.

Of course, for that to work properly, you have to intercept the database exception and translate it to a message string, since if the exception blows all the way back to the JSF framework you end up with the user seeing an ugly/useless stack trace page, instead.

In addition to catching exceptions, of course, you can set a message string to something like "No Data Available" if the datamodel has a row count of zero.


One of the most odious afflictions that Business has inflicted on the modern English language is "pro-active". Most of the time it's simply redundantly used in place of the simple old word "active". And a good deal of the rest of the time it means "You're not overworked enough yet, so go out and find more!"
 
 
subject: Populating Datatable from Database
 
Threads others viewed
Help with the State
A viewpage, a table and two backing beans
Iteration in JSF, how ?
commandLink actionListener
jsf DB access + sessions queries
developer file tools

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture