I'm trying do show a pdf in a JSF page but when the render occurs i have this problem as below. I have already tried a lot of solutions, but with no results. I'm opened to different modes to show the pdf, as the p:media (this one not worked neither).
Trouble:
GRAVE: Error in streaming dynamic resource.
java.lang.NullPointerException
at br.com.graflogic.utilities.presentationutil.scope.ViewScope.get(ViewScope.java:19)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:327)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:191)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1119)
at org.springframework.beans.factory.access.el.SpringBeanELResolver.getValue(SpringBeanELResolver.java:55)
at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:67)
at org.apache.myfaces.el.unified.resolver.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:179)
ViewScope:
@Override
public Object get(String name, @SuppressWarnings("rawtypes") ObjectFactory objectFactory) {
Map<String, Object> viewMap = FacesContext.getCurrentInstance().getViewRoot().getViewMap();
if (viewMap.containsKey(name)) {
return viewMap.get(name);
} else {
Object object = objectFactory.getObject();
viewMap.put(name, object);
return object;
}
}
Controller:
try {
final ByteArrayOutputStream out = new ByteArrayOutputStream();
final Document document = new Document();
PdfWriter.getInstance(document, out);
document.open();
for (int i = 0; i < 50; i++) {
document.add(new Paragraph("All work and no play makes Jack a dull boy"));
}
document.close();
content = new DefaultStreamedContent(new ByteArrayInputStream(out.toByteArray()), "application/pdf");
} catch (final Exception e) {
e.printStackTrace();
}
Page:
<pe:documentViewer height="500" value="#{relatorioController.content}" download="#{relatorioController.downloadFileName}"/>
Application:
PDF.js v1.5.188 (build: 0e2d50f) Mensagem: Unexpected server response (500) while retrieving PDF