I ‘m using Primefaces to upload files, I want to check the size of all the files that will be uploaded if the size is over the limit. I’ve managed to check the size of all files but I cant display any message.
FI: the check of file type is working and the message warning is displayed.
the scroll also is working.
What can I do?
<p:fileUpload id="attachmentUpload"
fileUploadListener="#{documentLibrary.checkFileSize}"
label="#{msg.upload}"
mode="advanced" multiple="true" styleClass="fileupload-buttonbar-white"
auto="true" update="attachmentPanel"
onstart="#{request.requestURI.contains('document/edit') ? 'PF('editWidgetVar').disable(), PF('documentWizardWidgetVar').hideNextNav(), PF('documentWizardWidgetVar').hideBackNav()' : 'PF('documentWizardWidgetVar').hideNextNav(), PF('documentWizardWidgetVar').hideBackNav()'}"
oncomplete="#{request.requestURI.contains('document/edit') ? 'PF('editWidgetVar').enable(), PF('outgoingDocumentWizardWidgetVar').showNextNav(), PF('outgoingDocumentWizardWidgetVar').showBackNav()' : 'PF('outgoingDocumentWizardWidgetVar').showNextNav(), PF('outgoingDocumentWizardWidgetVar').showBackNav()'}"
invalidFileMessage="#{of:format1(val['invalid_file_type'], documentLibrary.allowedExtensions)}"
allowTypes="#{documentLibrary.allowedExtensions}"
/>
<p:message id="fileWarnMessage" for="attachmentUpload" autoUpdate="true" />
and
public void checkFileSize(FileUploadEvent event) {
...
if(size > sizeLimit){
//MessageUtils.createBasicMessage("annex_exceed_3Mb", FacesMessage.SEVERITY_WARN, "form:documentEditComponent:attachmentUpload");
FacesContext.getCurrentInstance().addMessage("form:documentEditComponent:attachmentUpload", MessageUtils.createMessage("validation.messages", "file_exceed_limit", FacesMessage.SEVERITY_WARN));
PrimeFaces.current().ajax().update("form:documentEditComponent:attachmentUpload");
PrimeFaces.current().scrollTo("form:documentEditComponent:attachmentUpload");
}
}