• Post Reply Bookmark Topic Watch Topic
  • New Topic

managed property in constructor?

 
Dudley Dawson
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi-
I have a bean that has a managed property set in faces-config.xml
I want some other properties in that bean to be set based on that the value of that managed property. I thought the no-arg constructor would be a good place to do this, but it seems that the container first executes the constructor, THEN injects the managed properties. Through my debugging statements, I see that my managed property is null in the constructor, but then outputs the correct injected value in the resulting page.

What is the best practice for initializing objects based on managed properties?
 
Remko Strating
Ranch Hand
Posts: 893
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The following link maybe helpful.


A first class Inversion of Control (IoC) Facility for POJOs?


The last example is interesting for you...
 
Ryan Lubke
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Dudley Dawson:
Hi-
I have a bean that has a managed property set in faces-config.xml
I want some other properties in that bean to be set based on that the value of that managed property. I thought the no-arg constructor would be a good place to do this, but it seems that the container first executes the constructor, THEN injects the managed properties. Through my debugging statements, I see that my managed property is null in the constructor, but then outputs the correct injected value in the resulting page.

What is the best practice for initializing objects based on managed properties?


This behavior is per the specification.

If you require initialization logic to be executed, then I suggest you
migrate to JSF 1.2, and leverage the @PostConstruct and @PreDestory annotations.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!