2011-05-10 34 views
5

我正在使用<t:inputFileUpload />控制帶有JSF1.1的Tomahawk庫。 我的擴展篩選器和表單相應地設置爲允許上傳最大大小爲3 MB的文件。但問題是如果一個文件超過3 MB的表單不提交,但再次顯示,我不能爲它設置任何<h:message>如何顯示Tomahawk FileInput控件超出的大小限制

那麼如何告訴用戶文件上傳失敗。

我試過保留<h:messages globalOnly="true"但沒有任何顯示。

我已按照BalusC的博客文章設置我的上傳。

回答

4

異常詳細信息是EL可通過

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

因此,添加以下組件到頁面應該這樣做

<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']}" /> 

你可以最終建立一個PhaseListener果然它變成FacesMessage。請在beforePhase()beforePhase()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

謝謝你的詳細回覆。然而,我很抱歉地說當我遇到文件大小異常時,我得到了#{requestScope ['org.apache.myfaces.custom.fileupload.exception']}爲空。我正在使用JSF:1.1_02-b08 – 2011-05-10 15:30:32

相關問題