使用 tomahawk 上传文件 - 显示错误消息的问题
我使用
<h:form id="uploadForm" enctype="multipart/form-data">
<t:inputFileUpload id="fileupload" accept="image/*" storage="file"
value="#{fileUpload.uploadedFile}" styleClass="fileUploadInput"
required="true" validator="epacient.FileUploadValidator" validatorMessage="Napacna vrsta ali prevelika datoteka."/>
<h:message for="fileupload" style="color: red;" />
<br />
<h:commandButton value="Upload" id="fileUploadButton" action="#{fileUpload.upload}" />
<h:message for="uploadForm" style="color: red;" />
</h:form>
如果文件太大,它应该在
我该如何解决这个问题?
此致
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你不能用战斧做到这一点。但是,您可以在
ExtensionsFilter
uploadMaxFileSize >,但是当它发生时,它会硬抛出SizeLimitExceededException
这超出了所有 JSF 的范围,因此最终用户最终会得到一个丑陋的 HTTP 500 错误页面。尽管您可以在web.xml
中定义自定义错误页面(仅针对某些状态代码或异常类型显示),但您无法在FacesMessage
中很好地获取它最后您可以将其显示在h:message
中。做到这一点的唯一方法是允许无限大小的上传或 1GB 左右的限制(这可能很痛苦,但毕竟这只是客户自己的决定;)..为了避免抱怨客户,请确保表单中的某处有关于允许的最大尺寸的明确消息)。这样您就可以利用真正的
Validator
,它将在关联的h:message
中显示ValidatorException
,例如:You can't do this with Tomahawk. You can however configure the
uploadMaxFileSize
in theExtensionsFilter
, but when it occurs, it will hard-throw aSizeLimitExceededException
which goes beyond all the JSF thing so that the enduser ends up with an ugly HTTP 500 error page. Although you can define custom error pages inweb.xml
which should be displayed for certain status codes or exception types only, there's no way that you can get it nicely in aFacesMessage
which you at end can display in ah:message
.The only way to do this all nicely is to allow unlimited sized uploads or a 1GB limit or so (which may be a pain, but after all, it's just the client's own decision to do so ;) .. to avoid complaining clients, ensure that there's a clear message somewhere at the form about maximum allowed sizes). This way you can take benefit of a real
Validator
which will display theValidatorException
in the associatedh:message
, e.g:正如 Balus C 所说,这是一个众所周知的问题。请参阅:http://issues.apache.org/jira/browse/TOMAHAWK-1381< /a>
我认为 Tomahwak 的更高版本修复了这个问题。
Like Balus C said, it's a well known issue. See: http://issues.apache.org/jira/browse/TOMAHAWK-1381
I think a later version of Tomahwak fixes this.