我正在使用带有多个上传选项的 PrimeFaces fileUpload。在我的项目中,我想在图像上传期间发送电子邮件通知。我的问题是当我上传 10 张图片时,意味着同时发送了 10 封电子邮件通知。我想在上传 10 张图片时只发送一封电子邮件通知。我正在使用 primefaces 3.0 和 jsf 2.0。我该如何解决?
我的jsf页面:
<p:fileUpload id="imaload" fileUploadListener="#{photoUploadAction.handleImage}"
mode="advanced" multiple="true" process="@form"
update="messages,@form"
allowTypes="/(\.|\/)(gif|jpe?g|png)$/"/>
支持豆:
public void handleImage(FileUploadEvent event) throws IOException, EmailException {
try {
photoUploadVO.setDisabled("false");
//BufferedImage image = ImageIO.read(in);
ImageIO.write(resize(bufferedImage, 400, bufferedImage.getHeight()), "jpg", new File(tmpFile));
flag = photoUploadDaoService.uploadPhotos(photoUploadVO);
// profileImageService.uploadPhotos(profileImageBean);
if (flag == true) {
if(!loginBean.getType().equals("ngo") && !loginBean.getType().equals("admin") &&
!loginBean.getType().equals("ngo_coordinator") ){
volName = getVolunteerName(photoUploadVO.getUsrId(),photoUploadVO.getUser_type());
lst = apDao.retreiveSetup();
notification = lst.get(0).activity_email.toString();
email = lst.get(0).approval_toEmail.toString();
if(notification.equalsIgnoreCase(tmp)){
ecs.sendPhotoNotiFication(email,photoUploadVO,volName);
}
}
FacesMessage msg = new FacesMessage("Successfully Uploaded");
FacesContext.getCurrentInstance().addMessage(null, msg);
} else {
FacesMessage msg = new FacesMessage("Failure", event
.getFile().getFileName() + " to uploaded.");
FacesContext.getCurrentInstance().addMessage(null, msg);
}
} catch (IOException e) {
e.printStackTrace();
FacesMessage error = new FacesMessage(
FacesMessage.SEVERITY_ERROR,
"The files were not uploaded!", "");
FacesContext.getCurrentInstance().addMessage(null, error);
}
}
This is my email notification method inside handle upload methos:
ecs.sendPhotoNotiFication(email,photoUploadVO,volName);