Why does it call twice? Why does it set the first file from the table? Any ideas?
Here's my code:
Code: Select all
<p:dataTable id="offer_attachment_datatable"
widgetVar="offer_attachment_datatable"
var="attachment"
value="#{offerBean.offerAttachments}">
<p:column>
<f:facet name="header"/>
<p:commandLink ajax="false" actionListener="#{offerBean.prepareFile(attachment)}" title="#{attachment.name}">
<p:graphicImage value="/resources/themes/navigator_b2e/images/drive-download.png" />
<p:fileDownload value="#{offerBean.file}"/>
</p:commandLink>
</p:column>
</p:dataTable>
Code: Select all
private StreamedContent file;
private InputStream stream;
public void prepareFile(OfferAttachment attachment){
System.out.println("Attachment: "+attachment.getName());
stream = new ByteArrayInputStream(attachment.getAttachment());
file = new DefaultStreamedContent(stream, "text/plain", attachment.getName());
stream = null;
}
public StreamedContent getFile() {
System.out.println("File: "+file.getName());
return file;
}
public void setFile(StreamedContent file) {
this.file = file;
}