如何解决通过p:remoteCommand将xhtml中的参数传递给Java bean不起作用
我正在使用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 举报,一经查实,本站将立刻删除。