• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

Best practices for initializing backing bean?

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
And inside of my fortune cookie was this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic