I am trying to inject a Map or HashMap with @ManagedProperty.
I am getting an error like following -
javax.el.ELException: Cannot convert #{userBean.refs of type class java.lang.String to interface java.util.Map
I am unable to get the reason. Please Help.
Details -
1. I am using an action from demo.xhtml like -
<h:commandButton value="SHOW" action="#{hello.show }" />
2. in show.xhtml, I am access the value of map as
<h:outputText value="Refs" />
<h:outputText value="#{hello.refs }"/>
3. The managed beans are as -
@ManagedBean(name="hello")
@SessionScoped
public class HelloBean {
@ManagedProperty(value="#{userBean.refs")
private Map<
String,Long> refs;
//Setters & Getters
&
@ManagedBean(name="userBean")
@SessionScoped
public class TestBean {
private Map<String,Long> refs;
public TestBean() {
refs = new HashMap<String,Long>();
refs.put("aaa",new Long(111));
refs.put("bbb",new Long(222));
refs.put("ccc",new Long(333));
refs.put("ddd",new Long(444));
refs.put("eee",new Long(555));
}
//Setters & Getters
But, this is generating error. Output of console is like -
com.sun.faces.mgbean.ManagedBeanCreationException: Unable to set property refs for managed bean hello
...........
..........
at java.lang.Thread.run(Unknown Source)
Caused by: javax.el.ELException: Cannot convert #{userBean.refs of type class java.lang.String to interface java.util.Map
at org.apache.el.lang.ELSupport.coerceToType(ELSupport.java:424)
at org.apache.el.ExpressionFactoryImpl.coerceToType(ExpressionFactoryImpl.java:47)
at com.sun.faces.el.ELUtils.coerce(ELUtils.java:536)
at com.sun.faces.mgbean.BeanBuilder$Expression.evaluate(BeanBuilder.java:592)
at com.sun.faces.mgbean.ManagedBeanBuilder$BakedBeanProperty.set(ManagedBeanBuilder.java:606)
... 51 more
Mar 01, 2014 1:13:09 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for
servlet [Faces Servlet] in context with path [/JSF06ManagedBeans] threw exception [Unable to set property refs for managed bean hello] with root cause
javax.el.ELException: Cannot convert #{userBean.refs of type class java.lang.String to interface java.util.Map
at org.apache.......................Unknown Source)
at java.lang.Thread.run(Unknown Source)