I want to show x number of message/growl based on the files that were uploaded via the fileuploader in primeface.
Currently, it will only show the latest message. The rest will be not be shown. Is there anyway that the show last can be bypass? or another alternative?
So if I upload 4 files. Be it successful or not, I want it to show 4 messages. 1 for each files.
index.xhtml:
<h:form id="form">
<p:messages id="messages" autoUpdate="true" showDetail="true" closable="true" />
<p:fileUpload fileUploadListener="#{fileUploadAction.upload}"
mode="advanced" allowTypes="/(\.|\/)(asc)$/" dragDropSupport="true" update="messages" />
</h:form>
FileUploadAction.java:
public void upload(FileUploadEvent event)
{
String filename = event.getFile().getFileName();
try
{
copyFile(filename, event.getFile().getInputstream());
FacesContext.getCurrentInstance().addMessage(filename, new FacesMessage(FacesMessage.SEVERITY_INFO, "msg.header", filename + " is uploaded."));
}
catch (IOException e)
{
FacesContext.getCurrentInstance().addMessage(filename, new FacesMessage(FacesMessage.SEVERITY_ERROR, "err.header", e.getLocalizedMessage()));
}
}
public void copyFile(String fileName, InputStream in)
{
try
{
// write the inputStream to a FileOutputStream
OutputStream out = new FileOutputStream(new File(PropertiesUtil.LOCAL_PATH + fileName));
int read = 0;
byte[] bytes = new byte[1024];
while ((read = in.read(bytes)) != -1)
{
out.write(bytes, 0, read);
}
in.close();
out.flush();
out.close();
}
catch (IOException e)
{
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "err.header", e.getLocalizedMessage()));
}
}