我在使用@Named
注释时遇到了一些问题。例如,以下bean正常工作,它接收并上传文件:
@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;
}
}
但是,如果我将@ManagedBean
和@RequestedScope
替换为@Named
和@RequestScoped
,则会因此异常而失败:
javax.el.PropertyNotFoundException:目标无法访问,标识符'bean'已解析为null
我知道@Named
我的Netbeans项目中是否设置了不正确的版本或类似的内容?我也在Glassfish 4服务器上部署。
由于
答案 0 :(得分:0)
CDI 1.1是否需要beans.xml
?