Bom dia pessoal,
Estou desenvolvendo um projeto no qual estou tentando listar imagens do banco no componente <p:graphicImage/>
do primefaces, mas está dando o seguinte erro.
java.lang.NullPointerException
at com.sun.faces.mgbean.BeanManager$ScopeManager$ViewScopeHandler.getFromScope(BeanManager.java:563)
at com.sun.faces.mgbean.BeanManager$ScopeManager.getFromScope(BeanManager.java:477)
at com.sun.faces.mgbean.BeanManager.getBeanFromScope(BeanManager.java:240)
at com.sun.faces.el.ManagedBeanELResolver.resolveBean(ManagedBeanELResolver.java:242)
at com.sun.faces.el.ManagedBeanELResolver.getValue(ManagedBeanELResolver.java:116)
at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
at org.apache.el.parser.AstIdentifier.getValue(AstIdentifier.java:71)
at org.apache.el.parser.AstValue.getValue(AstValue.java:147)
at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:189)
at org.primefaces.application.DynamicContentStreamer.streamDynamicContent(DynamicContentStreamer.java:66)
at org.primefaces.application.DynamicContentStreamer.beforePhase(DynamicContentStreamer.java:57)
at com.sun.faces.lifecycle.Phase.handleBeforePhase(Phase.java:228)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:99)
at com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:111)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:508)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:79)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:851)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:405)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:278)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:515)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:637)
O meu DAO está assim
public InputStream maisUmTeste(){
String sql = " Select IMAGEM from produto where codigo = 1124";
con = ConnectionFactory.getMySQLConnection();
ImagemTeste imagemTeste = new ImagemTeste();
try{
PreparedStatement pstm = (PreparedStatement)con.prepareStatement(sql);
ResultSet rs = pstm.executeQuery();
if(rs.next()){
imagemTeste.setImagemInput(rs.getBinaryStream("IMAGEM"));
}
}catch(SQLException ex){
ex.printStackTrace();
}
return imagemTeste.getImagemInput();
}
O meu controller está assim
@ManagedBean(name="imagemControllerTeste")
@ViewScoped
public class ImagemControllerTeste {
private ImagemDAOTeste imagemDAO = new ImagemDAOTeste();
StreamedContent imagens = null;
InputStream dbStream = null;
//Getters e setters
public ImagemControllerTeste() throws SQLException {
dbStream = imagemDAO.maisUmTeste();
imagens = new DefaultStreamedContent(dbStream,"image/gif");
}
}
O meu xhtml está assim
<!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:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.prime.com.tr/ui">
<h:form prependId="false">
<p:graphicImage value="#{imagemControllerTeste.imagens}" />
</h:form>
</html>
Alguém sabe me dizer oq pode estar acontecendo?
Obrigada!