I am reading the book Core Java Server Faces 3rd Edition.
There is a sample of JSF ajax feature and I tried it with NetBeans9.1 and GlassFish V3.
However only when I use @ManagedBean, it works well. If I use @Named annotation, it seems that the @SessionScoped annotation doesn't work.
Because I saw that the default constructor of User bean was called four times when I click the Login button and the getGreeting() cannot catch the filed "name"'s value.
Joined: Feb 20, 2003
When I use @ManagedBean everything is ok:
When I use @Named instead, it is not ok anymore:
too many times the constructor method was called in each request.
Perhaps you use the same @SessionScoped annotation on both cases? Does the example you use do the same thing?
I have understood that if you use the @Named annotation (and are using the J2EE CDI (Contexts and Dependency Injection)) you should use the annotation used with enterprise beans i.e.
and if you use the @ManagedBean annotation (that is a JSF thing and not a "J2EE wide annotation") you use the JSF annotation meant for JSF beans i.e.
@ManagedBean is a JSF annotation and it wires itself into the faces-config. @Named is not. Although I believe that @Named can be used to set the management name of the bean instance, it doesn't inherently wire in to the JSF bean management subsystem.
Customer surveys are for companies who didn't pay proper attention to begin with.
I had the same issue and the @Named annotation started working correctly after I've included an empty beans.xml file under WEB-INF. Now I just use the @Named annotation and don't use @ManagedBean no longer.