aspose file tools*
The moose likes JSF and the fly likes Best practices for initializing backing bean? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Best practices for initializing backing bean?" Watch "Best practices for initializing backing bean?" New topic
Author

Best practices for initializing backing bean?

Marius Adamut
Greenhorn

Joined: Aug 09, 2007
Posts: 4
This is the scenario I'm facing on:
I have a configuration screen where I need to show/update some configuration parameters that are read from DB with one query.

This is how I'd like to do it, after the backing bean (with request scope) is created then read the parameters from DB and initialize the bean members so when the page gets rendered everything is in place. I could do this in the bean constructor but I need to use a static call to get the DB connection. I would rather use dependency injection for this, that means after the connection has been set then to do the query and initialize the bean. Although this would work my gut feeling says it is not right. I would prefer to have some event handler that I could implement and that would be called after the bean has been created and all the dependency set. I couldn't find anything like that, and all other solutions do not seem right.

Is it something that I'm missing here? Can this be implemented in another way elegantly?

Thanks.

Marius.
Ryan Lubke
Ranch Hand

Joined: Jun 20, 2007
Posts: 36
Originally posted by Marius Adamut:
This is the scenario I'm facing on:
I have a configuration screen where I need to show/update some configuration parameters that are read from DB with one query.

This is how I'd like to do it, after the backing bean (with request scope) is created then read the parameters from DB and initialize the bean members so when the page gets rendered everything is in place. I could do this in the bean constructor but I need to use a static call to get the DB connection. I would rather use dependency injection for this, that means after the connection has been set then to do the query and initialize the bean. Although this would work my gut feeling says it is not right. I would prefer to have some event handler that I could implement and that would be called after the bean has been created and all the dependency set. I couldn't find anything like that, and all other solutions do not seem right.

Is it something that I'm missing here? Can this be implemented in another way elegantly?

Thanks.

Marius.


Use JSF 1.2. You can annotation methods within your bean with the @PostConstruct or @PreDestroy annotations. In the case of @PostConstruct,
the method will be invoked on the bean *before* it is put into scope.
Marius Adamut
Greenhorn

Joined: Aug 09, 2007
Posts: 4
Thanks, that's what I was looking for. I thought that was a useful feature, I'm glad it got addressed in JSF 1.2
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Best practices for initializing backing bean?