Error documentViewer Missing PDF

Community Driven Extensions Project
Post Reply
david.avelino
Posts: 1
Joined: 16 Aug 2015, 23:10

16 Aug 2015, 23:19

good Night
I'm having the following problem in generating reports someone could help me

using:
primefaces 5.2
primefaces-extensions-3.2.0
pdf.js (1.1.215)

GeographicalReportMB

Code: Select all

@RequestScoped
@ManagedBean( name="geographicalReportMB" )
public class GeographicalReportMB extends AbstractMB implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -2128870632937814736L;
	
	@EJB
	private GeographicalReportDAO reportDAO;
	
	private StreamedContent content; 

	/**
	 * 
	 */
	@PostLoad
	public void init() {
		
	}
	
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public void countryReport() {
		InputStream relatorio = null;
		
		try {  
			HashMap parameters = new HashMap();
			
			List<Country> countries = new ArrayList<Country>();
			countries = reportDAO.listCountryAll();
			
			JasperReport jasperReport = ( JasperReport )JRLoader.loadObject( getClass().getClassLoader().getResourceAsStream( "br/com/webwan/weblicita/reports/country.jasper" ) );
		    jasperReport.setWhenNoDataType( WhenNoDataTypeEnum.ALL_SECTIONS_NO_DETAIL );
		     
			JRBeanCollectionDataSource dataSource = new JRBeanCollectionDataSource( countries );
			JasperPrint jasperPrint = JasperFillManager.fillReport( jasperReport, parameters, dataSource );
		      
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            JRPdfExporter exporter = new JRPdfExporter();
			
			exporter.setParameter( JRExporterParameter.JASPER_PRINT, jasperPrint );
			exporter.setParameter( JRExporterParameter.OUTPUT_STREAM, out );
			exporter.exportReport();
			
			relatorio = new ByteArrayInputStream( out.toByteArray() );
        } catch (JRException e) {  
            e.printStackTrace();  
        }  

		content = new DefaultStreamedContent( relatorio, "application/pdf" );  
	}

	public StreamedContent getContent() {
		return content;
	}

	public void setContent( StreamedContent content ) {
		this.content = content;
	}

}
View

Code: Select all

<!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://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:fn="http://java.sun.com/jsp/jstl/functions"
	xmlns:pe="http://primefaces.org/ui/extensions">
	
<h:body>
	<ui:composition template="/pages/protected/templates/master.xhtml">
		<ui:define name="templateIndexBody">
			<p:fieldset>
				<p:tabView id="tabView" dynamic="true">

					<p:tab id="tab0" title="#{msn.country}" rendered="#{accessMB.admin or accessMB.allowed('country_report')}">
						<h:form id="form_reportCountry" prependId="false">
							<p:commandButton id="button_countryNew1" value="#{msn.create}" title="#{msn.create}" 
										icon="ui-icon-plus" styleClass="button-add"
										action="#{geographicalReportMB.countryReport()}" type="submit"
										update=":alert :tabView:documentViewer_country" />
						</h:form>
						
						<p:fieldset legend="#{msn.report}" collapsed="false" toggleable="true" toggleSpeed="500" >
							<pe:documentViewer id="documentViewer_country" height="200" value="#{geographicalReportMB.content}" />
						</p:fieldset>
					</p:tab>

				</p:tabView>
			</p:fieldset>
			
			
		</ui:define>	
	</ui:composition>
</h:body>

</html>
Error:
PDF.js v1.0.21 (build: f954cde)
Message: Missing PDF "http://localhost:8080/javax.faces.resou ... a1932fba66".

Patrick-T80
Posts: 3
Joined: 07 Dec 2015, 23:56
Location: Altidona, Italy
Contact:

23 Feb 2016, 17:15

Hi David, it's a bit late to answer, but i've seen your post only now. In your backing bean you have missed to flush() and close youe ByteOutputStream, after exporter setup.

Post Reply

Return to “Extensions”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 4 guests