问题
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