使用PrimeFaces文件上传将值传递给辅助bean [英] Passing value to the backing bean with PrimeFaces file upload
问题描述
我正在尝试上传文件并使用PrimeFaces 3.5从选择框传递一个参数。
I am trying to upload the file and pass one parameter from select box with 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。
ConfiguratioBean is just a JSF @ViewScoped
bean which contains getter and setter for loaderName
.
我的ConfigurationAction bean:
My 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
中,并有一个命令按钮来上传单个文件,然后它正在运行。但我需要上传高级
。那么问题是如果PrimeFaces文件上传表格处于高级模式,如何将参数传递给支持bean?
I am receiving the file when I click upload, but the parameter loaderName
is always null
from the configurationBean
. If I try to switch file upload to simple mode, put the file as a value in configurationBean
and have a command button to upload the single file, then it is working. But I need upload to be advanced
. So the question is how to pass the parameter to the backing bean if PrimeFaces file upload form is in advanced mode?
推荐答案
使用< a href =http://www.primefaces.org/showcase/ui/remoteCommand.jsf =nofollow> 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>
未经测试但应该有效。
这篇关于使用PrimeFaces文件上传将值传递给辅助bean的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!