1
Bean:
package br.com.drogaria.bean;
import java.sql.SQLException;
import java.util.ArrayList;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.model.ListDataModel;
import br.com.drogaria.dao.FabricanteDAO;
import br.com.drogaria.domain.Fabricante;
@ManagedBean(name = "MBfabricantes")
@ViewScoped
public class FabricanteBean {
private ListDataModel<Fabricante> fResultSearch;
public ListDataModel<Fabricante> getfResultSearch() {
return fResultSearch;
}
public void setfResultSearch(ListDataModel<Fabricante> fResultSearch) {
this.fResultSearch = fResultSearch;
}
@PostConstruct
public void catalogo() {
FabricanteDAO fdao = new FabricanteDAO();
try {
ArrayList<Fabricante> list = fdao.listarTudo();
fResultSearch = new ListDataModel<Fabricante>(list);
} catch (SQLException e) {
e.printStackTrace();
}
}
}
Page:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:p="http://primefaces.org/ui"
template="/template/modeloSistema.xhtml">
<ui:define name="menu">
<ui:include src="/includes/menuPrincipal.xhtml" />
</ui:define>
<ui:define name="conteudo">
<p:dataTable emptyMessage="Nada encontrado :("
value="#{MBfabricantes.fResultSearch}" var="item">
<p:column headerText="Código">
<h:outputText value="#{item.codigo}" />
</p:column>
<p:column headerText="Descrição">
<h:outputText value="#{item.descricao}" />
</p:column>
</p:dataTable>
</ui:define>
</ui:composition>
Exception:
javax.servlet.Servletexception: An error occurred while injecting the resource into the Mbmanufacturers managed bean javax.faces.webapp.FacesServlet.service(Facesservlet.java:659) org.apache.Tomcat.websocket.server.WsFilter.doFilter(Wsfilter.java:52)
Post the full stacktrace, there must have been some error in the
PostConstruct
. And change theSQLException
by a more generic exception, just to check the stacktrace.– Wakim