0
I have an error trying to show a photo in the component graphicImage
of the Primefaces.
The photo can be in Base64 or Bytes. I’m using Primefaces 5.0 and JSF 2.2.
.xhtml
<p:dataTable id="tableFotos" var="foto" value="#{meuBean.listarFotos()}" emptyMessage="meu objeto não possui foto" >
<p:column headerText="Lista de fotos">
<p:graphicImage id="photo" value="#{meuBean.getImage(foto.descricao)}" cache="FALSE"/>
<h:outputText value="#{foto.descricao}"/>
</p:column>
</p:dataTable>
.java
public StreamedContent getImage(String descricao) {
for(Foto f : fotos){
if(f.getDescricao()!=null && f.getDescricao().equals(descricao)){
byte[] bytes;
if(f.getFoto()!=null)
bytes = f.getFoto();
else
bytes = Base64.decode(f.getFotoBase64());
return new DefaultStreamedContent(new ByteArrayInputStream(bytes));//o erro acontece aqui
}
}
return new DefaultStreamedContent();//o erro acontece aqui
}
As I showed even though I have no photo when returning only
new DefaultStreamedContent()
, the error also happens.
Error message:
java.io.IOException: java.lang.NullPointerException
org.primefaces.component.graphicimage.GraphicImageRenderer.encodeEnd(GraphicImageRenderer.java:42)
javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:919)
javax.faces.component.UIComponent.encodeAll(UIComponent.java:1863)
javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859)
org.primefaces.component.datatable.DataTableRenderer.encodeCell(DataTableRenderer.java:963)
org.primefaces.component.datatable.DataTableRenderer.encodeRow(DataTableRenderer.java:923)
org.primefaces.component.datatable.DataTableRenderer.encodeRows(DataTableRenderer.java:834)
org.primefaces.component.datatable.DataTableRenderer.encodeTbody(DataTableRenderer.java:781)
org.primefaces.component.datatable.DataTableRenderer.encodeTbody(DataTableRenderer.java:744)
org.primefaces.component.datatable.DataTableRenderer.encodeRegularTable(DataTableRenderer.java:258)
org.primefaces.component.datatable.DataTableRenderer.encodeMarkup(DataTableRenderer.java:220)
org.primefaces.component.datatable.DataTableRenderer.encodeEnd(DataTableRenderer.java:84)
javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:919)
org.primefaces.renderkit.CoreRenderer.renderChild(CoreRenderer.java:85)
org.primefaces.renderkit.CoreRenderer.renderChildren(CoreRenderer.java:68)
org.primefaces.component.panel.PanelRenderer.encodeContent(PanelRenderer.java:204)
org.primefaces.component.panel.PanelRenderer.encodeMarkup(PanelRenderer.java:121)
org.primefaces.component.panel.PanelRenderer.encodeEnd(PanelRenderer.java:58)
javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:919)
com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:312)
com.sun.faces.renderkit.html_basic.GridRenderer.renderRow(GridRenderer.java:185)
com.sun.faces.renderkit.html_basic.GridRenderer.encodeChildren(GridRenderer.java:129)
javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:889)
javax.faces.component.UIComponent.encodeAll(UIComponent.java:1856)
javax.faces.render.Renderer.encodeChildren(Renderer.java:176)
javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:889)
javax.faces.component.UIComponent.encodeAll(UIComponent.java:1856)
javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859)
org.primefaces.component.tabview.TabViewRenderer.encodeTabContent(TabViewRenderer.java:307)
org.primefaces.component.tabview.TabViewRenderer.encodeContents(TabViewRenderer.java:265)
org.primefaces.component.tabview.TabViewRenderer.encodeMarkup(TabViewRenderer.java:131)
org.primefaces.component.tabview.TabViewRenderer.encodeEnd(TabViewRenderer.java:71)
javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:919)
org.primefaces.renderkit.CoreRenderer.renderChild(CoreRenderer.java:85)
org.primefaces.renderkit.CoreRenderer.renderChildren(CoreRenderer.java:68)
org.primefaces.component.layout.LayoutUnitRenderer.encodeEnd(LayoutUnitRenderer.java:49)
javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:919)
javax.faces.component.UIComponent.encodeAll(UIComponent.java:1863)
javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859)
javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859)
javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859)
com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:456)
com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:133)
com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120)
com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:647)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
com.controllers.LoginFilter.doFilter(LoginFilter.java:41)
root cause
java.lang.NullPointerException
org.primefaces.util.DynamicResourceBuilder.build(DynamicResourceBuilder.java:50)
org.primefaces.component.graphicimage.GraphicImageRenderer.getImageSrc(GraphicImageRenderer.java:74)
org.primefaces.component.graphicimage.GraphicImageRenderer.encodeEnd(GraphicImageRenderer.java:40)
javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:919)
javax.faces.component.UIComponent.encodeAll(UIComponent.java:1863)
javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859)
org.primefaces.component.datatable.DataTableRenderer.encodeCell(DataTableRenderer.java:963)
org.primefaces.component.datatable.DataTableRenderer.encodeRow(DataTableRenderer.java:923)
org.primefaces.component.datatable.DataTableRenderer.encodeRows(DataTableRenderer.java:834)
org.primefaces.component.datatable.DataTableRenderer.encodeTbody(DataTableRenderer.java:781)
org.primefaces.component.datatable.DataTableRenderer.encodeTbody(DataTableRenderer.java:744)
org.primefaces.component.datatable.DataTableRenderer.encodeRegularTable(DataTableRenderer.java:258)
org.primefaces.component.datatable.DataTableRenderer.encodeMarkup(DataTableRenderer.java:220)
org.primefaces.component.datatable.DataTableRenderer.encodeEnd(DataTableRenderer.java:84)
javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:919)
org.primefaces.renderkit.CoreRenderer.renderChild(CoreRenderer.java:85)
org.primefaces.renderkit.CoreRenderer.renderChildren(CoreRenderer.java:68)
org.primefaces.component.panel.PanelRenderer.encodeContent(PanelRenderer.java:204)
org.primefaces.component.panel.PanelRenderer.encodeMarkup(PanelRenderer.java:121)
org.primefaces.component.panel.PanelRenderer.encodeEnd(PanelRenderer.java:58)
javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:919)
com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:312)
com.sun.faces.renderkit.html_basic.GridRenderer.renderRow(GridRenderer.java:185)
com.sun.faces.renderkit.html_basic.GridRenderer.encodeChildren(GridRenderer.java:129)
javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:889)
javax.faces.component.UIComponent.encodeAll(UIComponent.java:1856)
javax.faces.render.Renderer.encodeChildren(Renderer.java:176)
javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:889)
javax.faces.component.UIComponent.encodeAll(UIComponent.java:1856)
javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859)
org.primefaces.component.tabview.TabViewRenderer.encodeTabContent(TabViewRenderer.java:307)
org.primefaces.component.tabview.TabViewRenderer.encodeContents(TabViewRenderer.java:265)
org.primefaces.component.tabview.TabViewRenderer.encodeMarkup(TabViewRenderer.java:131)
org.primefaces.component.tabview.TabViewRenderer.encodeEnd(TabViewRenderer.java:71)
javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:919)
org.primefaces.renderkit.CoreRenderer.renderChild(CoreRenderer.java:85)
org.primefaces.renderkit.CoreRenderer.renderChildren(CoreRenderer.java:68)
org.primefaces.component.layout.LayoutUnitRenderer.encodeEnd(LayoutUnitRenderer.java:49)
javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:919)
javax.faces.component.UIComponent.encodeAll(UIComponent.java:1863)
javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859)
javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859)
javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859)
com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:456)
com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:133)
com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120)
com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:647)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
com.controllers.LoginFilter.doFilter(LoginFilter.java:41)
Primefaces 5.0 and JSF 2.2
– Skywalker