<managed-bean>
<managed-bean-name>businessDelegate</managed-bean-name>
<managed-bean-class>com.delegates.BusinessDelegate</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
<managed-bean>
<managed-bean-name>manageMyBean</managed-bean-name>
<managed-bean-class>com.beans.ManageMyBean</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
<managed-property>
<property-name>businessDelegate</property-name>
<value>#{requestScope.businessDelegate}</value>
</managed-property>
</managed-bean>
The above injects businessDelegate into manageMyBean. It also creates a new
instance if it is needed.
JSF IoC container is not that powerful, I prefer to use Spring and then use
the Spring delegating variable resolver.
You could also write your own JSF variable resolver and then manage the
businessDelegate w/o putting it into scope.
-----Original Message-----
From: Ondrej Svetlik [mailto:[EMAIL PROTECTED]
Sent: Wednesday, June 21, 2006 7:37 PM
To: MyFaces Discussion
Subject: Re: managed properties
Dhananjay Prasanna wrote:
> Hi I want a managed bean to create itself a managed service. This is
> what Im trying because I would like a new instance of the service
> (businessDelegate) for each instance of manageMyBean. Is there any way I
> can accomplish this?
>
>
>
> <managed-bean>
>
> <managed-bean-name>manageMyBean</managed-bean-name>
>
> <managed-bean-class>com.beans.ManageMyBean</managed-bean-class>
>
> <managed-bean-scope>request</managed-bean-scope>
>
>
>
> <managed-property>
>
> <property-name>businessDelegate</property-name>
>
>
> <property-class>com.delegates.BusinessDelegate</property-class>
>
> </managed-property>
>
> </managed-bean>
>
>
>
> The above code complains that there is no initial value for the managed
> property (obviously). But I am not aware that EL supports the new
> operator so Im not sure how to go about this. Any ideas or am I forced
> to declare another managed bean and refer to it?
>
>
>
> Thanks,
>
>
>
> Dhanji.
>
> This correspondence is for the named persons only.
> It may contain confidential or privileged information or both.
> No confidentiality or privilege is waived or lost by any mis transmission.
> If you receive this correspondence in error please delete it from your
> system immediately and notify the sender.
> You must not disclose, copy or relay on any part of this correspondence,
> if you are not the intended recipient.
> Any opinions expressed in this message are those of the individual
> sender except where the sender expressly,
> and with the authority, states them to be the opinions of the Department
> of Emergency Services, Queensland.
>
Hello,
why don't you simply create the instance in the constructor of the bean?
class ManageMyBean {
public ManageMyBean() {
this.businessDelegate = new com.delegates.BusinessDelegate();
}
}
best regards
Ondrej Svetlik