Hi,
I have read that the @Named annotation is used to specify CDI and is preferable over the @ManagedBean annotation when creating beans (if someone can clarify this it would be appreciated, I haven't got the book I read this from on hand at the moment to give the exact reasons). For some reason though I can't switch between the two in my project (using netbeans) without an error being generated when I process a form. I started my project with CDI enabled, which inserts the required beans.xml file into my WEB-INF folder. Everything was working with the @Named annotation but when I switch to the @ManagedBean annotation I get an error on clicking my command button. I have restarted the server, redeployed my war file, rebuilt the project but nothing seems to work. Is it a case that you have to pick one way of annotating your beans and stick with it? My code is extremely simple and just for
testing purposes:
Person.java (imports, getters, setters excluded)
index.xhtml
This works ok but when I switch the @Named annotation to @ManagedBean I get the following error on clicking the command button...
/index.xhtml @13,76 value="#{person.name}": Target Unreachable, identifier 'person' resolved to null
It works vice versa as well i.e. when I start my project without CDI enabled and no beans.xml file and use the @ManagedBean annotation it works; but if I then add a beans.xml file to WEB-INF and switch to the @Named annotation I get the same error.
Any ideas?
Thanks,
Alan