如何将参数发送到 PrimeFaces fileUpload 中的 fileUploadListener [英] How to send parameter to fileUploadListener in PrimeFaces fileUpload
本文介绍了如何将参数发送到 PrimeFaces fileUpload 中的 fileUploadListener的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我创建模型时,我想为模型保存图像.我正在使用 PrimeFaces fileUpload 组件.当我保存图片时,我想知道特定图像指的是哪个模型.这就是为什么我需要将模型的 id 发送到支持 bean.
When I create a model I would like to save images for a model. I am using PrimeFaces fileUpload component. When I save pictures I want to know to which model particular image refers to. That's why I need to send id of a model to backing bean.
是否有可能将模型的id发送到fileUploadListener?
<h:form enctype="multipart/form-data">
<p:panelGrid columns="2">
<h:outputLabel for="hotelName" value="#{msg.hotelName}"/>
<p:inputText value="#{apartmentNew.name}" id="hotelName"/>
<h:outputLabel for="hotelDescription" value="#{msg.hotelDescription}"/>
<p:inputText value="#{apartmentNew.description}" id="hotelDescription"/>
<h:outputLabel for="hotelImages" value="#{msg.hotelImages}"/>
<h:form enctype="multipart/form-data">
<p:fileUpload id="hotelImages"
fileUploadListener="#{apartments.handleImageUpload}"
mode="advanced"
sizeLimit="10000000"
allowTypes="/(.|/)(gif|jpe?g|png)$/">
</p:fileUpload>
</h:form>
</p:panelGrid>
<p:commandButton id="saveApartmentButton" value="#{msg.save}" action="save"/>
<p:commandButton id="cancelCreationApartmentButton" value="#{msg.cancel}"
action="cancel"/>
</h:form>
推荐答案
不是通过请求参数.您可以通过组件属性来实现.
Not via request parameters. You can do so via component attributes.
例如
<p:fileUpload ...>
<f:attribute name="foo" value="bar" />
</p:fileUpload>
与
String foo = (String) event.getComponent().getAttributes().get("foo"); // bar
这篇关于如何将参数发送到 PrimeFaces fileUpload 中的 fileUploadListener的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文