Fileupload 和 PrettyFaces 和 JSF 2.2 [英] Fileupload and PrettyFaces and JSF 2.2
问题描述
我尝试了以下解决方案:Primefaces FileUpload with PrettyFaces 和 JSF 2.2.3
I've tried the solution from: Primefaces FileUpload with PrettyFaces and JSF 2.2.3
但它不适用于少数文件(在 tomcat 7.0.50 下测试).
But it doesn't work for a few files (tested under tomcat 7.0.50).
其中一个文件是:http://ftp.carnet.hr/misc/apache//xerces/j/source/Xerces-J-src.2.11.0-xml-schema-1.1-beta.zip
有没有人有更好的解决方案来解决这个问题(除了删除 urlmapping)?
Has someone a better solution for this problem (other than removing the urlmapping)?
没有抛出错误/异常!文件显示在 PrimeFaces FileUpload 中,但未触发侦听器!JSF2.2 inputFile 也不行!
There is no error/exception thrown! File is shown in the PrimeFaces FileUpload, but the listener is not fired! JSF2.2 inputFile doesn't work, too!
推荐答案
我已经找到了解决问题的方法.
I've found a solution for my problem.
问题是用于上传的表单的操作属性.PrettyFaces 将 action 属性更改为新的漂亮网址.
The problem is the action attribute of the forms which are used for the upload. PrettyFaces changes the action attribute to the new pretty-url.
如果您将 action 属性更改为真实的 url(带有 .xhtml、.jsf、...的那个),fileupload 将再次工作,并且不需要上下文文件(tomcat)中的 allowCasualMultipartParsing="true" 条目没有了.
If you change the action attribute to the real url (the one with .xhtml,.jsf,...) the fileupload works again and the allowCasualMultipartParsing="true" entry in the context-file(tomcat) is not needed anymore.
要更改路径,将此脚本放入视图(您的 xhtml 文件;需要 jquery):
To change the path place this script into the view (your xhtml-file; jquery needed):
<script type="text/javascript">
$(document).ready(function() {
$("form[enctype='multipart/form-data']").attr("action","#{request.contextPath}/test/fileupload.xhtml");
});
</script>
现在文件上传适用于我的所有文件,包括那些不起作用的文件(即使使用 allowCasualMultipartParsing="true" 解决方案).
Now the fileupload is working for all of my files including the ones which not worked (even with allowCasualMultipartParsing="true" solution).
使用 Primefaces4.0 FileUpload-Component 测试.
Tested with Primefaces4.0 FileUpload-Component.
还有其他更好的解决方案吗?
Is there any other better solution?
这篇关于Fileupload 和 PrettyFaces 和 JSF 2.2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!