1

我正在尝试使用 PrimeFaces 3.5 上传文件并从选择框中传递一个参数。

这是我的表格:

<h:form id="idAssessmentsUploadForm" enctype="multipart/form-data">

    <h:panelGrid cellspacing="10" styleClass="standard-panel" columns="2" id="idAssessmentsUploadPanelGrid">

        <h:outputText value="#{msg['application.assessmentsUploadRequest.loader']}"/>
        <p:selectOneMenu id="idLoader"
                         style="width: 230px;"
                         required="true"
                         value="#{configurationBean.loaderName}">

            <f:selectItems value="#{configurationBean.loaders}"/>

        </p:selectOneMenu>

    </h:panelGrid>

    <p:fileUpload fileUploadListener="#{configurationAction.processConfigurationUpload}"
                  allowTypes="/(\.|\/)(gif|jpe?g|png)$/"
                  update="messages"
                  mode="advanced"/>

</h:form>

ConfiguratioBean 只是一个 JSF @ViewScopedbean,它包含用于loaderName.

我的 ConfigurationAction bean:

@ManagedBean(name = Beans.CONFIGURATION_ACTION)
@ViewScoped
public class ConfigurationAction extends BaseAction {

    public void processConfigurationUpload(FileUploadEvent event) {

        ConfigurationBean configurationBean = getBean(Beans.CONFIGURATION_BEAN);

        UploadedFile file = event.getFile();

        addInfoMessage("Upload Successful");
    }

}

单击上传时,我正在接收文件,但参数loaderName始终null来自configurationBean. 如果我尝试将文件上传切换到简单模式,将文件作为值放入configurationBean并有一个命令按钮来上传单个文件,那么它就可以工作了。但我需要上传advanced。那么问题是如果 PrimeFaces 文件上传表单处于高级模式,如何将参数传递给 backing bean?

4

1 回答 1

3

为此使用remoteCommand。例如:

<h:form id="idAssessmentsUploadForm" enctype="multipart/form-data">

    <h:panelGrid cellspacing="10" styleClass="standard-panel" columns="2" id="idAssessmentsUploadPanelGrid">

        <h:outputText value="#{msg['application.assessmentsUploadRequest.loader']}"/>
        <p:selectOneMenu id="idLoader"
                         style="width: 230px;"
                         value="#{configurationBean.loaderName}"
                         required="true">

            <f:selectItems value="#{configurationBean.loaders}"/>

        </p:selectOneMenu>

    </h:panelGrid>

    <p:fileUpload fileUploadListener="#{configurationAction.processConfigurationUpload}"
                  allowTypes="/(\.|\/)(gif|jpe?g|png)$/"
                  required="true"
                  onstart="loadProperty()"
                  update="messages"
                  mode="advanced"/>

    <p:remoteCommand name="loadProperty">
        <f:setPropertyActionListener for="idLoader"
                                     value="#{configurationBean.loaderName}"
                                     target="#{configurationBean.loaderName}"/>
    </p:remoteCommand>

</h:form>

未经测试,但应该可以工作。

于 2013-05-31T07:55:20.787 回答