问题描述
我正在使用p:fileUpload
组件,我需要从该组件传递给Java Bean类,即要上传的文件数。
PrimeFaces.widgets.<widget_name>.files.length
处提供文件计数。
因此,我试图通过p:remoteCommand
将此值传递给java bean,但是由于某种原因,调用了action
中定义的方法,但未传递参数。
我正在使用Primefaces 2.1 ...我知道这是史前版本,但我需要修复使用此版本Primefaces的应用程序中的一个错误。因此,不可能升级到较新的版本。
这是我的代码段。
XHTML:
<p:fileUpload
fileUploadListener="#{staticView.handleSingleFileUpload}"
mode="advanced" multiple="true" id="upload"
widgetVar="fileUploadWidget"
label="#{text['forms.filesView.upload']}"
uploadLabel="#{text['forms.filesView.doUpload']}"
cancelLabel="#{text['forms.filesView.doCancel']}"
dragDropSupport="true"
update="@form :editorForm:msgs :editorForm:filesDetail"
onstart="setFilesCount({filesCount:PrimeFaces.widgets.fileUploadWidget.files.length});">
</p:fileUpload>
<p:remoteCommand name="setFilesCount" action="#{staticView.setFilesCountSelectedForUpload}" />
Java bean:
public void setFilesCountSelectedForUpload() {
String countInString = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("filesCount");
filesCountSelectedForUpload = Integer.parseInt(countInString);
}
public void handleSingleFileUpload(FileUploadEvent event) {
try {
UploadedFile file = event.getFile();
processFileUpload(file);
} finally {
filesCountSelectedForUpload--;
if (filesCountSelectedForUpload <= 0) {
enableOverwrite();
}
}
}
我在做什么错? 您能帮我发现问题,还是给我建议如何在客户端进行调试?
当我将此PrimeFaces.widgets.fileUploadWidget.files.length
写入浏览器控制台时,我能够获取要上传的所选文件的数量。
对于此问题的任何帮助,我们将不胜感激。 谢谢。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)