1

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

D-Dᴙum
  • 7,278
  • 8
  • 50
  • 90
  • I think the other question should have been marked as 'duplicate' since it was asked after the above. – D-Dᴙum Apr 28 '16 at 18:44

1 Answers1

0

Do you have a beans.xml, as needed by CDI 1.1?

John Ament
  • 10,860
  • 1
  • 29
  • 44
  • ah no. I'll try that... – D-Dᴙum Dec 21 '13 at 09:26
  • CDI 1.1 detects implicit beans by default. Ìf you have `@Named @RequestScoped`, then `beans.xml` should not be required for the bean to be discovered. – Harald Wellmann Dec 21 '13 at 10:52
  • I have another problem now with CDI and tomahawk but I've started it as a new question here http://stackoverflow.com/questions/20719382/tommahawk-myfaces-and-cdi – D-Dᴙum Dec 21 '13 at 13:14