[jboss-user] [JBoss Tools] - Initializing a Managed Bean's Property

Denis Golovin do-not-reply at jboss.com
Tue Apr 6 23:47:18 EDT 2010


Denis Golovin [http://community.jboss.org/people/dgolovin] replied to the discussion

"Initializing a Managed Bean's Property"

To view the discussion, visit: http://community.jboss.org/message/535973#535973

--------------------------------------------------------------
> 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 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);
}

"

--------------------------------------------------------------

Reply to this message by going to Community
[http://community.jboss.org/message/535973#535973]

Start a new discussion in JBoss Tools at Community
[http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2128]

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20100406/f04c854d/attachment.html 


More information about the jboss-user mailing list