Document Viewer usage

Community Driven Extensions Project
Post Reply
Ksyusha
Posts: 2
Joined: 22 Jun 2016, 09:30

23 Jun 2016, 12:00

Hello everybody,
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>
dialog:

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>
Attachment entity:

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;
	}
downloadFile() method from managed bean:

Code: Select all

public StreamedContent  downloadFile(Attachment rc) {
	ByteArrayInputStream inputStream = new
			 ByteArrayInputStream(rc.getData());
			
			 file = new DefaultStreamedContent(inputStream, rc.getContentType(),
					 rc.getFileName());
			}
return file;
}

User avatar
Melloware
Posts: 230
Joined: 22 Apr 2013, 15:48

30 Dec 2016, 22:59

To answer both your questions:

1. See the showcase example and look at the Resource example on this page for what name="" and library="" does. http://www.primefaces.org/showcase-ext/ ... /basic.jsf

2. This question was answered here: http://forum.primefaces.org/viewtopic.php?f=14&t=43602
PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces 6.1 / PF Extensions 6.1.1

User avatar
Melloware
Posts: 230
Joined: 22 Apr 2013, 15:48

28 Jan 2017, 16:38

It is fixed in PF Extensions 6.1. You can use a new property "download" to set the name like...

Code: Select all

<pe:documentViewer height="500" value="#{basicDocumentViewerController.content}" download="extensions-rocks.pdf"/>
PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces 6.1 / PF Extensions 6.1.1

Post Reply
  • Information
  • Who is online

    Users browsing this forum: No registered users and 2 guests