Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
815 views
in Technique[技术] by (71.8m points)

file upload - How to send parameter to fileUploadListener in PrimeFaces fileUpload

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.

Is there any possibility to send id of model to 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>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Not via request parameters. You can do so via component attributes.

E.g.

<p:fileUpload ...>
    <f:attribute name="foo" value="bar" />
</p:fileUpload>

with

String foo = (String) event.getComponent().getAttributes().get("foo"); // bar

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...