i want to use your Document Viewer component from Primefaces Extensions 6.0.0 in my project. I have two questions about Document Viewer usage.
1. What is the meaning of attributes "name" and "library"?
2. I tried to use Document Viewer with StreamedContent as value, but the document name is "document.pdf" when i try to save my document. Is it possible to save pdf-document with another name?
commandButton opens dialog with Document Viewer
Code: Select all
<p:commandButton value="Download" icon="ui-icon-arrowthick-1-s"
oncomplete="PF('preview').show()"
update=":#{p:component('preview')}"
actionListener="#{receipientController.downloadFile(attachment)}">
</p:commandButton>
Code: Select all
<p:dialog id="preview" widgetVar="preview"
modal="true" resizable="false" >
<pe:documentViewer height="600" width="1000" value="#{receipientController.file}" >
</pe:documentViewer>
</p:dialog>
Code: Select all
public class Attachment implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(name="ATTACHMENT_ID")
private BigDecimal attachmentId;
@Lob
@Column(name="DATA")
private byte[] data;
@Column(name="CONTENT_TYPE")
private String contentType;
@Column(name="FILE_NAME")
private String fileName;
public byte[] getData() {
return this.data;
}
Code: Select all
public StreamedContent downloadFile(Attachment rc) {
ByteArrayInputStream inputStream = new
ByteArrayInputStream(rc.getData());
file = new DefaultStreamedContent(inputStream, rc.getContentType(),
rc.getFileName());
}
return file;
}