Publicidade

Guilherme Costa Lopes

Members
  • Total de itens

    12
  • Registro em

  • Última visita

Reputação

0 Comum

Sobre Guilherme Costa Lopes

  1. Ao tentar iniciar uma página do sistema mostra este erro. Vou colocar os códigos: DAO package br.com.netsoft.desif.dao.endereco; import java.io.Serializable; import java.util.List; import javax.persistence.EntityManager; import javax.persistence.Query; import br.com.netsoft.desif.model.endereco.PaisEntity; public class PaisDao implements Serializable { private static final long serialVersionUID = 1402488530698938353L; final private String hql = " p FROM PaisEntity p "; EntityManager em; public List<PaisEntity> listarPaises() { StringBuilder hqlSelect = new StringBuilder(hql); final String query = "SELECT " + hqlSelect; Query querySelect = em.createQuery(query); @SuppressWarnings("unchecked") List<PaisEntity> resultList = querySelect.getResultList(); return resultList; } } ENTITY package br.com.netsoft.desif.model.endereco; import java.io.Serializable; import javax.persistence.Column; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.SequenceGenerator; public class PaisEntity implements Serializable { private static final long serialVersionUID = 7784827196506672790L; private Long id; private String descricao; @Id @Column(name = "pai_id") @SequenceGenerator(name = "enderecos.end_pais_pai_id_seq", sequenceName = "enderecos.end_pais_pai_id_seq", allocationSize = 1) @GeneratedValue(generator = "enderecos.end_pais_pai_id_seq", strategy = GenerationType.SEQUENCE) public Long getId() { return id; } public void setId(Long id) { this.id = id; } @Column(name = "pai_descricao") public String getDescricao() { return descricao; } public void setDescricao(String descricao) { this.descricao = descricao; } } CONTROLLER package br.com.netsoft.desif.controler.endereco; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import javax.annotation.PostConstruct; import javax.enterprise.context.RequestScoped; import javax.faces.bean.ManagedBean; import br.com.netsoft.desif.dao.endereco.PaisDao; import br.com.netsoft.desif.model.endereco.PaisEntity; @ManagedBean(name = "paisControler") @RequestScoped public class PaisControler extends PaisEntity { private static final long serialVersionUID = -8396738159447021720L; private List<PaisEntity> paises; private PaisDao paisDao; public List<PaisEntity> getPaises() { if (paises == null) { return new ArrayList<PaisEntity>(); } return paises; } public void setPaises(List<PaisEntity> paises) { this.paises = paises; } @PostConstruct public void init() { System.out.println("Página inicial de países."); @SuppressWarnings("unused") List<PaisEntity> paisesBusca = paisDao.listarPaises(); ArrayList<PaisEntity> paises = (ArrayList<PaisEntity>) paisDao.listarPaises(); for (Iterator<?> iterator = paises.iterator(); iterator.hasNext();) { PaisEntity pais = (PaisEntity) iterator.next(); pais.setId(pais.getId()); pais.setDescricao(pais.getDescricao()); paises.add(pais); } this.setPaises(paises); } public String getMensagem() { return "Teste"; } } VISÃO <!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:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html"> <h:head> <title>Hello JSF!</title> </h:head> <h:body> #{paisControler.mensagem} <h:dataTable var="pais" value="#{paisControler.paises}"> <h:column headerText="Id"> <h:outputText value="#{pais.id}" /> </h:column> <h:column headerText="Year"> <h:outputText value="#{pais.descricao}" /> </h:column> </h:dataTable> </h:body> </html> Erro: mar 21, 2017 8:08:40 AM com.sun.faces.application.view.FaceletViewHandlingStrategy handleRenderException GRAVE: Error Rendering View[/public/index.xhtml] javax.el.ELException: /public/index.xhtml: Um erro ocorreu ao realizar a injeção de recurso no bean gerenciado paisControler at com.sun.faces.facelets.compiler.TextInstruction.write(TextInstruction.java:90) at com.sun.faces.facelets.compiler.UIInstructions.encodeBegin(UIInstructions.java:82) at com.sun.faces.facelets.compiler.UILeaf.encodeAll(UILeaf.java:183) at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859) at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859) at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:443) at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131) at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:337) at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120) at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219) at javax.faces.webapp.FacesServlet.service(FacesServlet.java:647) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:478) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:80) at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:624) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:341) at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:783) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:798) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1441) at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Unknown Source) Caused by: com.sun.faces.mgbean.ManagedBeanCreationException: Um erro ocorreu ao realizar a injeção de recurso no bean gerenciado paisControler at com.sun.faces.mgbean.BeanBuilder.invokePostConstruct(BeanBuilder.java:227) at com.sun.faces.mgbean.BeanBuilder.build(BeanBuilder.java:103) at com.sun.faces.mgbean.BeanManager.createAndPush(BeanManager.java:409) at com.sun.faces.mgbean.BeanManager.create(BeanManager.java:269) at com.sun.faces.el.ManagedBeanELResolver.resolveBean(ManagedBeanELResolver.java:244) at com.sun.faces.el.ManagedBeanELResolv
  2. O que é este erro ?
  3. Mas como fazer ? Pelo que entendi tenho que fazer no jsp. Tem alguma sugestão ?
  4. Este campo é preenchido corretamente por uma consulta feita no DAO. O problema é que não está aceitando o objeto como nulo ou como o valor pelo ID. O campo da entidade é Estou com este erro do log do eclipse. O jsp está assim para este campo: Meu jsp O que pode ser ?
  5. GRAVE: Servlet.service() for servlet [appServlet] in context with path [/extensao] threw exception [Request processing failed; nested exception is java.lang.IllegalArgumentException: org.hibernate.hql.ast.QuerySyntaxException: Professor is not mapped [ SELECT p FROM Professor p]] with root cause org.hibernate.hql.ast.QuerySyntaxException: Professor is not mapped [ SELECT p FROM Professor p] Classe Professor package br.newtonpaiva.extensao.model; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.Table; @Entity @Table(name = "tb_professor") public class Professor { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long cod_professor; private Long nom_nome; public Long getCod_professor() { return cod_professor; } public void setCod_professor(Long cod_professor) { this.cod_professor = cod_professor; } public Long getNom_nome() { return nom_nome; } public void setNom_nome(Long nom_nome) { this.nom_nome = nom_nome; } } Classe controller package br.newtonpaiva.extensao.controller; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import br.newtonpaiva.extensao.model.Professor; import br.newtonpaiva.extensao.model.ProfessorRepository; @Controller @RequestMapping("professores") public class ProfessorController { @Autowired ProfessorRepository repository; @RequestMapping(method = RequestMethod.GET) public String index(Model model) { List<Professor> listaProfessores = repository.listar(); model.addAttribute("listaProfessores", listaProfessores); return "professores"; } } Classe Repository package br.newtonpaiva.extensao.model; import java.util.List; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; import org.springframework.stereotype.Repository; @Repository public class ProfessorRepository { @PersistenceContext private EntityManager manager; /** * Lista todos os professores */ @SuppressWarnings("unchecked") public List<Professor> listar() { return manager.createQuery("SELECT p FROM Professor p").getResultList(); } /** * Lista todos os professores por nome */ @SuppressWarnings("unchecked") public List<Professor> listarNome(String professor) { return manager.createQuery("SELECT p FROM Professor p WHERE p.nom_nome LIKE '%" + professor + "%' ") .getResultList(); } }