开发者

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 globalOnl开发者_开发技巧y="true" but nothing gets shown.

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


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));
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜