@Dayson_Rodrigues escreveu:
estou criando meu projeto usando JSF e Primeface e quero usar CDI, alguém poderia me dar uma Força?
1 - Já coloquei a dependencia do Weld,
2 - Dentro WebApp criei uma Pasta META-INF onde tem um arquivo beans.xml
3 - adicionei no web.xml<listener> <listener-class>org.jboss.weld.environment.servlet.Listener</listener-class> </listener> <resource-env-ref> <resource-env-ref-name>BeanManager</resource-env-ref-name> <resource-env-ref-type>javax.enterprise.inject.spi.BeanManager</resource-env-ref-type> </resource-env-ref>
Esse é o Meu DAO
public class FabricanteDAO implements Serializable {`
private static final long serialVersionUID = 1L; private EntityManager em; public void salvar(Fabricante fabricante) { em.merge(fabricante); } public List<Fabricante> buscarTodos() { return em.createQuery("from Fabricante", Fabricante.class).getResultList(); } public void excluir(Fabricante fabricante) throws NegocioException { try { Fabricante fabricanteTemp = this.buscarPeloCodigo(fabricante.getCodigo()); em.remove(fabricanteTemp); em.flush(); } catch (PersistenceException e) { throw new NegocioException("Fabricante não pode ser excluído."); } } public Fabricante buscarPeloCodigo(Long codigo) { return em.find(Fabricante.class, codigo); }
}
Mensagens: 2
Participantes: 2