我正在尝试上传文件并使用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
的getter和setter。
我的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文件上传表格处于高级模式,如何将参数传递给支持bean?
答案 0 :(得分: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>
未经测试但应该有效。