Getting data from DB upon application startup
2 posts in topic
Flat View  Flat View

Posted By:   bruce_riches
Posted On:   Friday, March 13, 2009 06:50 PM


Just getting into using JSF.
How would I access a DB before any pages are rendered in the UI?
My first page needs to display information from a DB table(s). I have tried to define a Listener class containing a contextinitialized method in the web.xml file but this does not seem to work.

I have seen a solution that defines a managed bean that populates a list and an associated reference in an
There has to be a more elegant way to do this.

Thanks for any help.

Re: Getting data from DB upon application startup

Posted By:   bruce_riches  
Posted On:   Thursday, March 19, 2009 08:19 PM

I have created a Listener class which get s the info from the DB. I then call the jsp and the data is there. So far, so good. However, I want to iterate thru the results using the dataTable tag and I cannot seem to make this work.
At the point at which I get the data I'm assigning it to a property on a managed bean. The value somehow disappears between this and the jsp.
This is driving me nuts!

Re: Getting data from DB upon application startup

Posted By:   Anonymous  
Posted On:   Monday, March 16, 2009 07:32 PM

You would generally write some type of backing bean yourself inside of one of the more advanced frameworks, like JBoss Seam or the Spring framework. They allow you to have beens defined as regular pojo's and then have a factory style lazy initialization of the data.

Without some type of framework you are pretty much on your own about how to do it, there are some crude ways, like you mentioned but they are hard to maintain and do not fit very well with the rest of the application.

Another option could be Gracelets, it uses groovy together with JSF/Facelets and allows you to write hot reloadable views (with factories defined right inside) and controllers (backing beans) in groovy which can accomplish what you are looking for as well.

Hope that gives you an idea
About | Sitemap | Contact