Bean property becomes null when using CDI @Named Annotation [duplicate]

风流意气都作罢 提交于 2019-12-11 15:32:48

问题


I am using JSF2+CDI in a Tomcat 7 Container. I found a strange problem, I have got one @RequestScoped managed bean annotated with @Named annotation, Iam using its properties on a Facelet page. In that page three consecutive dropdown list is arranged. when the page loads i have initialized the first dropdown list using its getter method. In that same method i have initialized the properties of second and third dropdown boxes. But the second and third properties becomes null in the page. I have checked the getter methods of the second and third properties, I found that all those properties are null and even the first property which has been initialized by the first getter method also displayed as null. But when I changed the @Named annotation to @ManagedBean i could initialize the values correctly.


回答1:


Make sure you import the correct package. If you use CDI with @Named, you need to import javax.enterprise.context.RequestScoped;. However, if you use @ManagedBean, you need to import javax.faces.bean.RequestScoped;



来源:https://stackoverflow.com/questions/8664526/bean-property-becomes-null-when-using-cdi-named-annotation

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!