org.primefaces.application.resource.StreamedContentHandler.handle Error in streaming dynamic resource. Stream Closed
<?xml version='1.0' encoding='UTF-8' ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://xmlns.jcp.org/jsf/html" xmlns:f="http://xmlns.jcp.org/jsf/core" xmlns:p="http://primefaces.org/ui"> <h:head> <title>Facelet Title</title> <style> *{ margin: 0px; padding:0px; } #pdf_div{ height: 100%; width: 100%; } .ui-widget-content{ margin-top: 0px; } </style> </h:head> <h:body> <h2>Internalization Language Example</h2> <h:form enctype="multipart/form-data" id="submit_form"> <p:messages closable="true"/> <div id="upload-button"> <p>Browse</p> <h:inputFile value="#{userData.image}"> <f:passThroughAttribute name="accept" value="*.pdf"/> <f:ajax event="change" listener="#{userData.load_stream_Content}" render=":pdf_preview"/> </h:inputFile> </div> <p:commandButton ajax="false" update="submit_form" value="Upload" action="#{userData.doUpload()}"> </p:commandButton> </h:form> <p:outputPanel id="pdf_preview" > <p:media width="100%" height="700px" value="#{userData.streamedContent}" cache="false" player="pdf"/> </p:outputPanel> </h:body> </html>
//imports @ManagedBean(name = "userData", eager = true) @SessionScoped public class UploadController implements Serializable { public UploadController() { } StreamedContent streamedContent; private InputStream inputStream; public void load_stream_Content() throws Exception { inputStream=image.getInputStream(); // String fileName = image.getSubmittedFileName(); FacesContext context = FacesContext.getCurrentInstance(); if (context.getCurrentPhaseId() == PhaseId.RENDER_RESPONSE) { streamedContent = new DefaultStreamedContent(); } else { streamed = true; String fs = Paths.get(image.getSubmittedFileName()).getFileName().toString(); streamedContent=new DefaultStreamedContent(inputStream, "application/pdf", fs); } streamed = true; } public StreamedContent getStreamedContent() { return streamedContent; } public void setStreamedContent(StreamedContent streamedContent) { this.streamedContent = streamedContent; } //getter setter private Part image; private boolean upladed; boolean streamed = false; }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)