我正在尝试使用 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 @ViewScoped
bean,它包含用于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?