6

I am using <t:inputFileUpload /> control of the Tomahawk library with JSF1.1. My Extension Filters and form are set accordingly to allow a file of max-size 3 MB to be uploaded. But the problem is if a File is more than 3 MB the form doesnt get submitted but is shown again , and i cant set any <h:message> for it .

So how do i tell the User the file upload has failed.

I have tried keeping <h:messages globalOnly="true" but nothing gets shown.

I have followed BalusC blog post for setting up my uploads.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Archan Mishra
  • 887
  • 7
  • 18

1 Answers1

5

The exception detail is available in EL by

#{requestScope['org.apache.myfaces.custom.fileupload.exception']}

So, adding the following component to the page should do it

<h:outputText value="File upload failed! #{requestScope['org.apache.myfaces.custom.fileupload.exception']}" 
    styleClass="error" rendered="#{not empty requestScope['org.apache.myfaces.custom.fileupload.exception']}" />

You could eventually create a PhaseListener which turns it into a FacesMessage. Do the following in beforePhase() of PhaseId.RENDER_RESPONSE

Object fileuploadException = requestMap.get("org.apache.myfaces.custom.fileupload.exception");
if (fileuploadException != null) {
    facesContext.addMessage(null, new FacesMessage("File upload failed! " + fileuploadException));
}
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Thank you for such a detailed reply. However I am sorry to say I am getting #{requestScope['org.apache.myfaces.custom.fileupload.exception']} as null when I encounter a File size exception. I am using JSF : 1.1_02-b08 – Archan Mishra May 10 '11 at 15:30
  • this works, I use validade in js to and backend with this code. https://stackoverflow.com/questions/10508477/restricting-file-upload-size-in-jsf/57906775#57906775 – Artur Todeschini Sep 12 '19 at 12:33