It's a bit of a work-around, but I believe allowing
map.property to use get/put is part of the EL syntax. Perhaps look at
breaking out the initialization function into another holder
bean.
public class MyMapHolder {
...
public Dependency getMyDependency() {
return myDependency;
}
public Dependency setMyDependency(Dependency newDependency) {
myDependency = newDependency;
// initialize contained myMap using myDependency
}
...
public MyMap getMyMap() {
return myMap;
}
...
public Dependency getMyDependency() {
return myDependency;
}
public Dependency setMyDependency(Dependency newDependency) {
myDependency = newDependency;
// initialize contained myMap using myDependency
}
...
public MyMap getMyMap() {
return myMap;
}
public void setMyMap(MyMap newMyMap)
{
myMap = newMyMap;
myMap = newMyMap;
}
}
}
<managed-bean>
<managed-bean-name>myMap</managed-bean-name>
<managed-bean-class>MyMap</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
<managed-bean-name>myMap</managed-bean-name>
<managed-bean-class>MyMap</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
<managed-bean>
<managed-bean-name>myMapHolder</managed-bean-name>
<managed-bean-class>MyMapHolder</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
<managed-bean-name>myMapHolder</managed-bean-name>
<managed-bean-class>MyMapHolder</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
<managed-property>
<property-name>myMap</property-name>
<property-class>MyMap</property-class>
<value>#{myMap}</value>
</managed-property>
<managed-property>
<property-name>myDependency</property-name>
<property-class>Dependency</property-class>
<value>#{someOtherBean}</value>
</managed-property>
</managed-bean>
<property-name>myMap</property-name>
<property-class>MyMap</property-class>
<value>#{myMap}</value>
</managed-property>
<managed-property>
<property-name>myDependency</property-name>
<property-class>Dependency</property-class>
<value>#{someOtherBean}</value>
</managed-property>
</managed-bean>
Neal Haggard
Senior Systems
Developer
Knowledge Management
Center
SAS Institute
From: Michael [mailto:[EMAIL PROTECTED]
Sent: Thursday, September 15, 2005 10:11 AM
To: MyFaces Discussion
Subject: Re: Map managed bean with managed properties
Should a bug be filed on this or is it desired behavior? I looked through the spec for guidance here but I didn't see anything.
Thanks,
Michael
On 9/15/05, "Ricardo R.
RamÃrez Valenzuela" <[EMAIL PROTECTED]>
wrote:
Does this actually work? I don't think you can use expressions in the
value for initialization.
What I do when I want to "inject" a value to another bean is get the
bean via the faces context, for example I do a
getManagedBean("detailsBean").setDetail(someObject)
(I attach the code for my getManagedBean method below)
public final static Object getManagedBean(String beanName)
{
FacesContext facesContext = FacesContext.getCurrentInstance();
Application a = facesContext.getApplication();
ValueBinding binding = a.createValueBinding("#{" + beanName + "}");
return binding.getValue (facesContext);
}
I wonder if this is the best practice....
Ricardo
Michael wrote:
> Hi all,
>
> I have a managed bean that implements the Map interface. The bean
> also has a dependency that needs to be injected. I thought I'd be
> able to configure the bean like this:
>
> public class MyMap implements Map {
> ...
> public Dependency getMyDependency() {
> return myDependency;
> }
> public Dependency setMyDependency(Dependency newDependency) {
> myDependency = newDependency;
> // initialize contained map using myDependency
> }
> ...
> // Impementation of map interface...
> }
>
> <managed-bean>
> <managed-bean-name>myMap</managed-bean-name>
> <managed-bean-class>MyMap</managed-bean-class>
> <managed-bean-scope>request</managed-bean-scope>
> <managed-property>
> <property-name>myDependency</property-name>
> <property-class>Dependency</property-class>
> <value>#{someOtherBean}</value>
> </managed-property>
> </managed-bean>
>
> The problem I'm running into is that PropertyResolverImpl.setValue
> checks to see if the bean is an instance of Map and if so, calls
> put(property, value). So instead of calling MyMap.setMyDependency, it
> is calling MyMap.put and passing the key = "myDependency" and the
> value = #{someOtherBean}.
>
> Any suggestions?
>
> Thanks,
> Michael