-
1. Re: Initializing a Managed Bean's Property
dgolovin Apr 6, 2010 8:22 PM (in response to jabailo)1 of 1 people found this helpfulAs it says here http://www.oracle.com/technology/tech/java/newsletter/articles/jsf_pojo/index.html, you need bean to be registered in faces config with default values. Then if you have a reference to it through EL expression somewhere on page it should just work.
But it is rather JSF runtime related question then JSF tooling support. JSF Tools could be helpful here if it would be able outguess problem you faced and warn you that your bean might be not initialized properly at some point for some reason. I'm not sure it is possible since there are no source snippets in your question.
-
2. Re: Initializing a Managed Bean's Property
jabailo Apr 6, 2010 8:39 PM (in response to dgolovin)I do have a default value set.
The value is a connection to a server...that is used in a method when making a connection to the server. (LDAP).
I was hoping that at the time my JSF page called the bean, it would have read in the default values and be able to use them in executing the method called by JSF. But that doesn't appear to be the case.
I was looking for something like a properties file that is read on instantiation. Again it seems like manged properties of the managed bean would do this -- but I am not sure at what point the bean is instantiated and what is required to get the default value read into the bean. From what I read it seemed like it should just happen automatically once I established the managed property and added a default value.
-
3. Re: Initializing a Managed Bean's Property
dgolovin Apr 6, 2010 11:47 PM (in response to jabailo)John Bailo wrote:
I do have a default value set.
I was hoping that at the time my JSF page called the bean, it would have read in the default values and be able to use them in executing the method called by JSF. But that doesn't appear to be the case.
It should depend on bean scope. For instance request scope bean will get re-initialized on each page refresh.
John Bailo wrote:
I was looking for something like a properties file that is read on instantiation. Again it seems like manged properties of the managed bean would do this -- but I am not sure at what point the bean is instantiated and what is required to get the default value read into the bean. From what I read it seemed like it should just happen automatically once I established the managed property and added a default value.
I'm just guessing but why not this approach I get from http://www.icefaces.org
"The simplest way is to use Chaining in the faces config and call your init method. You'll have to add an empty Object of String parameter to your a setInit method.
... <managed-property> <property-name>init</property-name> <value>java.lang.Object</value> </managed-property> ....
From a design point of view I don't like my beans doing a whole lot of initialization work I usually make a naming distinction and move all initialization code into controller. The controller can initialized the bean directly by a callback.
... <managed-property> <property-name>init</property-name> <value>#{myController}</value> </managed-property> ....
where
pubic void setInit(MyController controller){ controller.init(this); }
"