我有uploadBean,它是sessionScoped。我想在oncomplete中调用远程命令myRemoteFunction
:
<h:form enctype="multipart/form-data">
<p:fileUpload fileUploadListener="#{uploadBean.handleFileUpload}" mode="advanced"
allowTypes="/(\.|\/)(mdb)$/"
description="Select File"
dragDropSupport="true"
multiple="false"
fileLimit="1"
update="growl"
widgetVar="fileUploadWidget"
oncomplete="PF('fileUploadWidget').reset(); myRemoteFunction()"/>
<p:remoteCommand name="myRemoteFunction" action="#{uploadBean.remoteFunction}"/>
<script>
PrimeFaces.widget.FileUpload.prototype.reset = function() {
this.clearMessages();
return this.init(this.cfg);
}
</script>
</h:form>
在豆方面:
public void remoteFunction(){
//some logic here after the file is uplodaded
}
public void handleFileUpload(FileUploadEvent event) {
//some growl messages are set here
// and let the progress bar vanish immediately
}
当我设置远程命令&#34; myRemoteFunction&#34;我收到此错误消息:
Caused by: javax.servlet.ServletException: org.apache.tomcat.util.http.fileupload.FileUploadBase$InvalidContentTypeException: the request doesn't contain a multipart/form-data or multipart/mixed stream, content type header is application/x-www-form-urlencoded; charset=UTF-8
我不想在handleFileUpload函数中调用remoteFunction。因为当我调用它时,进度条显示文件已完全上传,但在进程退出hadleFileUpload函数之前它不会消失。因为remoteFuction中的逻辑可能需要5秒到15秒。
如何实现这一目标?感谢。
答案 0 :(得分:0)
我发现你的代码可能有两件事可能出错。第一个,不一定是错的,但是,
PF('fileUploadWidget').reset();
我不知道上传小部件上有重置功能,但您可以注册,或者我不熟悉的某个版本,但请检查您的代码javascript错误。
第二,肯定是错的,你需要用paranthesis myRemoteFunction()
调用 myRemoteFunction ,否则它会默默地忽略。