Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show size limit exceeded for Tomahawk FileInput control

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.

like image 848
Archan Mishra Avatar asked May 10 '11 14:05

Archan Mishra


1 Answers

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));
}
like image 78
BalusC Avatar answered Oct 20 '22 10:10

BalusC