Passing parameter from xhtml through p:remoteCommand to java bean not working

為{幸葍}努か 提交于 2021-01-29 06:45:59

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!