I use Primefaces 5.1, Primefaces Extensions 3.0.0 and GlassFish 4.0 in my project and have many problems with pe:documentViewer. My code is:
in xhtml
<f:event listener="#{previewComponent.onPrerender}" type="preRenderView"/> <p:tab title="#{text['attach.documento']}" class="borderless nopadding"> <pe:documentViewer value="#{previewComponent.file2}"/> </p:tab>
in bean
public class PreviewComponent extends BasePage implements Serializable {
private String filePath; private StreamedContent file2; //events public void onPrerender(ComponentSystemEvent event) { try { if (this.filePath == null) { if (log.isDebugEnabled()) { log.debug("OnPreRender: filePath is null!"); } ByteArrayOutputStream out = new ByteArrayOutputStream(); Document document = new Document(); PdfWriter.getInstance(document, out); document.open(); for (int i = 0; i < 50; i++) { document.add(new Paragraph("Ficheiro não encontrado.")); } document.close(); setFile2(new DefaultStreamedContent(new ByteArrayInputStream(out.toByteArray()), "application/pdf")); } else { if (log.isDebugEnabled()) { log.debug("OnPreRender: filePath is " + this.filePath); } String fileName = FilenameUtils.getName(filePath); String mimeType = this.getFacesContext().getExternalContext().getMimeType(fileName); if (log.isDebugEnabled()) { log.debug("fileName: " + fileName); log.debug("mimeType: " + mimeType); } setFile2(new DefaultStreamedContent(new FileInputStream(filePath), mimeType)); } } catch (Exception e) { if (log.isDebugEnabled()) { log.debug("OnPreRender: error is " + e.getMessage()); } } } //GETTERS and SETTERS public String getFilePath() { return filePath; } public void setFilePath(String filePath) { this.filePath = filePath; } public StreamedContent getFile2() { return file2; } public void setFile2(StreamedContent file2) { this.file2 = file2; }
}
And initialy i have the follow error:
SEVERE: Exception during lifecycle processing java.lang.RuntimeException: There is no web component by the name of Faces Servlet here.
After i add this in web.xml:
<servlet-mapping>
<servlet-name>faces</servlet-name>
<url-pattern>*.xhtml</url-pattern>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
And after this i have more errors. Why? Give me some answers please :D