Ioa*_*nis 7 ajax jsf file-upload mojarra jsf-2.2
尝试实现JSF 2.2示例我有以下代码:
<h:form prependId="false" enctype="multipart/form-data">
<!-- Now it's the AJAX file upload component -->
<h:inputFile id="fileUpload" value="#{someBean.file}" >
<f:ajax />
</h:inputFile>
<h:commandButton value="Upload" />
</h:form>
Run Code Online (Sandbox Code Playgroud)
根据一些JSF 2.2,这应该工作,但在我的情况下它给了我以下错误:
请求不包含multipart/form-data或multipart/mixed流,内容类型头是application/x-www-form-urlencoded; charset = UTF-8
查看请求虽然我已正确设置我的表单enctype,但部分请求提交:
内容类型:application/x-www-form-urlencoded; charset = UTF-8 Faces-Request:partial/ajax
请注意,web.xml也被修改为:
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
<multipart-config>
<location>c:\dotmp</location>
<max-file-size>20848820</max-file-size>
<max-request-size>418018841</max-request-size>
<file-size-threshold>1048576</file-size-threshold>
</multipart-config>
</servlet>
Run Code Online (Sandbox Code Playgroud)
我正在使用Mojarra 2.2.0-m15,但也尝试使用早期版本.有谁知道关于这个问题的任何有用的信息,我认为这是一个错误?
我不知道发生了什么事,因为我以前没见过这个.当使用今天的Mojarra 2.2.1快照时,以下构造对我有用,您可以从JSF 2.2中的新功能中提到的" 实现jar "链接下载该快照.
<h:form enctype="multipart/form-data">
<h:inputFile value="#{bean.file}" required="true">
<f:ajax listener="#{bean.handleFileUpload}" render="@form" />
</h:inputFile>
<h:messages />
</h:form>
Run Code Online (Sandbox Code Playgroud)
同
private Part file;
public void handleFileUpload(AjaxBehaviorEvent event) {
System.out.println("file size: " + file.getSize());
System.out.println("file type: " + file.getContentType());
System.out.println("file info: " + file.getHeader("Content-Disposition"));
}
// ...
Run Code Online (Sandbox Code Playgroud)
我建议尝试更新的Mojarra版本.显然,较旧的Mojarra版本中存在一个错误,该错误无法multipart/form-data
使用<iframe>
最终导致此错误的黑客创建正确的请求.该mXX
版本的测试版反正也不应将其生产的依据.理论上这个错误也可能是浏览器特定的,但它在Chrome 26,Firefox 20和IE 10中对我来说当前很好用.
我看到的唯一问题是隐藏<iframe>
在Chrome和Firefox中仍然可见,如下所示:
似乎他们忘记frameborder
了0
在生成中设置属性<iframe>
.我已经报告了2861号问题.
归档时间: |
|
查看次数: |
16315 次 |
最近记录: |