I try to learn JSF and encountered on a problem connected with ManagedProperty. However I have tried to use it, it always failed - null exception pointer. What am I doing wr
@ManagedProperty
is managed bean annotaion, that can't be used with CDI. In above code, you used CDI bean i.e. @Named
that is default in JSF 2.2. In this case you can't use ManagedProperty. Please read following line copied from Java EE docs of ManagedBean.
If this annotation is present on a class that does not have the ManagedBean annotation, the implementation must take no action on this annotation.
For details see the link:
http://docs.oracle.com/javaee/6/api/javax/faces/bean/ManagedProperty.html
So, use @Inject
instead of @ManagedProperty
for CDI bean.
@Inject
private User user;
Note that a getter/setter is unnecessary here.