1
I’m having trouble displaying images on a datagrid using both img and graphicImage passing to these tags the path of the database. Could someone help?
I’m using Tomcat 8.
The last way I tried was this:
No Bean:
public StreamedContent getImage(Noticia noticia) {
File arquivo = new File(noticia.getImagem()); // caminho do banco de dados
FileInputStream inputStream = null;
try {
if(arquivo.exists()){
inputStream = new FileInputStream(arquivo);
}else{
return new DefaultStreamedContent();
}
} catch (Exception e) {
e.printStackTrace();
}
return new DefaultStreamedContent(inputStream);
}
In xhtml:
<p:dataGrid id="noticias" var="noticia" value="#{noticiaBean.listaTesteNoticia}" paginator="true" rows="20" emptyMessage="Não existem notícias.">
<f:facet name="header">Lista de Notícias</f:facet>
<p:panel header="Notícia">
<p:column>
<p:graphicImage value="#{noticia.imagemMontada}" cache="false" /> <!-- objeto do tipo StreamedContent-->
</p:column>
</p:panel>
</p:dataGrid>
In the database you have this path: c: imagens_manager test.png
This image shows in debug mode when trying to mount inputStream:
Exception Lançado:
GRAVE: Error in streaming dynamic resource. null
out 26, 2015 4:10:37 PM org.apache.catalina.core.StandardWrapperValve invoke
GRAVE: Servlet.service() for servlet [Faces Servlet] in context with path [/sisgerenciador] threw exception
java.io.IOException: java.lang.NullPointerException
at org.primefaces.application.PrimeResourceHandler.handleResourceRequest(PrimeResourceHandler.java:122)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:643)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:516)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1086)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:659)
at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:223)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1558)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1515)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
I also tried to use the virtual directory of Tomcat (C: Program Files Apache Software Foundation Tomcat 8.0 conf Catalina localhost img), but it does not work.
xml images.
<?xml version="1.0" encoding="UTF-8"?>
<Context docBase="C:\imagens_gerenciador"></Context>
Could put the source code?
– rray
@rray Edited the post for better understanding.
– Sron Lemos
Do you have <h:form> on your page? You need to use Streamedcontent?
– Rodrigo
@Rodrigo Tem <h:form>. It doesn’t have to be via Streamedcontent.
– Sron Lemos
Your images are actually being created in the folders you set?
– Weslley Tavares
Thank you for answering, the solution I got is just below.
– Sron Lemos