问题
I'm using p:fileUpload
component from which I need to pass to java bean class, number of files which will be uploaded.
Count of files is available here PrimeFaces.widgets.<widget_name>.files.length
.
So I'm trying to pass this value to java bean through p:remoteCommand
, but for some reason method defined in action
parameter is called, but parameter is not passed.
I'm using Primefaces 2.1 ... I know that is prehistorical version, but I need to fix one bug in application which is using this version of Primefaces. So there is not possibility to upgrade to newer version.
Here is my code snippets.
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();
}
}
}
During debugging I can see this:
What am I doing wrong? Could you help me to find the problem, or give me an advice how to debug this on client side?
When I write this PrimeFaces.widgets.fileUploadWidget.files.length
to browser console, I'm able to get count of selected files for upload.
I would appreciate any help with this problem. Thanks.
来源:https://stackoverflow.com/questions/63819389/passing-parameter-from-xhtml-through-premotecommand-to-java-bean-not-working