I'm having some problems using the @Named
annotation. For example the following bean works correctly, it receives and uploaded file:
@ManagedBean
@RequestScoped
public class Bean {
private UploadedFile uploadedFile;
public void submit() throws IOException {
String fileName = FilenameUtils.getName(uploadedFile.getName());
String contentType = uploadedFile.getContentType();
byte[] bytes = uploadedFile.getBytes();
// Now you can save bytes in DB (and also content type?)
FacesContext.getCurrentInstance().addMessage(null,
new FacesMessage(String.format("File '%s' of type '%s' successfully uploaded!", fileName, contentType)));
}
public UploadedFile getUploadedFile() {
return uploadedFile;
}
public void setUploadedFile(UploadedFile uploadedFile) {
this.uploadedFile = uploadedFile;
}
}
However if I replaces the @ManagedBean
and @RequestedScope
with @Named
and @RequestScoped
it fails with this exception:
javax.el.PropertyNotFoundException: Target Unreachable, identifier 'bean' resolved to null
I know @Named
do I have an incorrect version set in my Netbeans project or something along those lines? I'm deploying on a Glassfish 4 server too.
Thanks