PrimeFaces fileupload调用p:remoteCommand指定方法



在PrimeFaces 6.0中,我需要在上传文件之前对其进行处理,然后在完成浏览按钮时尝试调用另一种方法。我尝试使用remoteCommand,但行不通。

<p:fileUpload allowTypes="/(.|/)(csv|zip)$/"
        value="#{geoDataBean.file}" mode="simple" oncomplete="loadCountries();"
        update="countriesDropdownPanel">
</p:fileUpload>
<p:remoteCommand name="loadCountries" process="@this"
        action="#{geoDataBean.loadCountries()}"/>       
<h:panelGroup id="countriesDropdownPanel">
    <p:selectCheckboxMenu 
            widgetVar="countryCode" 
            id="countryCodeId"
            value="#{geoDataBean.selectedCountryCodes}"
            label="#{geoDataBean.label}" 
            multiple="true"
            panelStyle="width:198px">
        <p:ajax 
                event="toggleSelect" 
                update="countryCodeId"
                listener="#{geoDataBean.update}" />
        <f:selectItems value="#{geoDataBean.countryCodeList}" />
    </p:selectCheckboxMenu>
</h:panelGroup>
<h:commandButton value="Import" action="#{geoDataBean.importGeoData}" />

我需要对文件进行处理,因为我需要查看文件中存在哪些国家以导入它们。

我用uploadedfile。

尝试在onChange中调用该功能,而不是oncomplete

<p:fileUpload allowTypes="/(.|/)(csv|zip)$/"
                value="#{geoDataBean.file}" mode="simple" onchange="loadCountries();" update="countriesDropdownPanel">
                </p:fileUpload>

如果您需要在客户端访问文件,也可以使用以下jQuery。这将适用于支持输入类型文件的浏览器。

$("input[type=file]").on("change", function() {
        // Do your stuff with this.files
        loadCountries();
});

相关内容

最新更新