Estou tendo um problema de consulta - JSF [RESOLVIDO]

7 respostas
diegocrs

Olá estou tendo um problema em consulta usando o JSF e Hibernate. Estar tudo certo... porém nao estou adivinhando o erro.

As paginas são essas:

<%@ page language="java" contentType="text/html" 
pageEncoding="ISO-8859-1"
%>
   <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
   <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
   
   <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Resultado de Pesquisas de Clientes</title>
    </head>
    <body>
        <f:view>
            <h:messages />
            <h3>Cliente(s) Encontrado(s)</h3>
            <h:form>
                <h:dataTable value='#{RelbugsController.buscarCliente}'
                  var='item' border="1" cellpadding="2" cellspacing="0">
                    <h:column>
                      <f:facet name="header">
                        <h:outputText value="codigo"/>                            
                      </f:facet> 
                      <h:outputText value="#{item.codigo}"/> 
                    </h:column>
                    <h:column>
                     <f:facet name="header">
                        <h:outputText value="Cliente"/>                            
                     </f:facet> 
                     <h:outputText value="#{item.cliente}"/> 
                    </h:column>                
                </h:dataTable> 
            </h:form>
          </f:view>  
    </body>
</html>
[b]E Também tem essa:[/b]
<%@ page language="java" contentType="text/html" 
pageEncoding="ISO-8859-1"
%>
   <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
   <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
   
   <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Busca Clientes</title>
    </head>
    <body>
      <f:view>
          <h:form id="buscar">
              <h:panelGrid columns="2">
                  <f:facet name="header">
                      <h:outputText value="Busca de Cliente"/>
                  </f:facet>

                      <h:outputText value="Cliente: "/>
                      <h:inputText size="30" id="cliente" value="#{RelbugsController.keysearch}"/>
                                        
              </h:panelGrid>
              <h:commandButton value="Consultar" action="pesquisado"/>
          </h:form>
      </f:view>    
    </body>
</html>

E tenho essa pra fazer a consulta:

package relbugs.dao;
import java.util.List;
import javax.management.Query;
import pontualtecnologia.Cliente;
import relbugs.util.ConnectRelbugsFactory;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.Transaction;

public class RelbugsDAO implements InterfaceRelbugs {

    private Session session;
    
    public void salvar(Cliente cliente){
        session = ConnectRelbugsFactory.getInstance();         
        Transaction t = null;
        
        try {
            t = session.beginTransaction();
            session.save(cliente);
            t.commit();
        } catch (HibernateException e) {
            e.printStackTrace();
            t.rollback();
        }
        finally{
            session.close();
        }
    }

public void excluir(Cliente cliente){
   session = ConnectRelbugsFactory.getInstance();
        Transaction t = null;
        
        try {
            t = session.beginTransaction();
            session.delete(cliente);
            t.commit();
        } catch (HibernateException e) {
            e.printStackTrace();
            t.rollback();
        }
        finally{
            session.close();
        }
}

public void atualizar(Cliente cliente){
       session = ConnectRelbugsFactory.getInstance();
        Transaction t = null;
        
        try {
            t = session.beginTransaction();
            session.update(cliente);
            t.commit();
        } catch (HibernateException e) {
            e.printStackTrace();
            t.rollback();
        }
        finally{
            session.close();
        }
}
public List todosClientes(){
    session = ConnectRelbugsFactory.getInstance();
    List list = session.createQuery("from Cliente").list();
    return list;
}
public List consultarClientes(String cliente){
    session = ConnectRelbugsFactory.getInstance();
        org.hibernate.Query query = session.createQuery(
            "from Cliente cli where cli.cliente like :cliente");
    List list = query.setString("cliente", "%"+cliente+"%").list();
    
    return list;
}
}

Então o que estar errado no codigo... ja fiz varias modificações e nada...

7 Respostas

g4j

Olá!

Experimente mudar o nome do método para getBuscarCliente

diegocrs

Ja tentei e tbm nao funcionou

g4j

e como esta teu faces-config.xml? Poste o trecho onde declara o ManagedBean RelbugsController

diegocrs

Esse é meu faces-config.xml:

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE faces-config PUBLIC 
"-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1///EN" 
"http://java.sun.com/dtd/web-facesconfig_1_1.dtd">

<!-- =========== FULL CONFIGURATION FILE ================================== -->

<faces-config>
 <managed-bean>
     <managed-bean-name>RelbugsController</managed-bean-name>
     <managed-bean-class>
       relbugs.controller.RelbugsController
     </managed-bean-class>
     <managed-bean-scope>session</managed-bean-scope>
 </managed-bean>
 
 <navigation-rule>
     <display-name>mostrarRelbugs</display-name>
     <from-view-id>/mostrarRelbugs.jsp</from-view-id>
     <navigation-case>
         <from-outcome>editar</from-outcome>
         <to-view-id>/atuRelbugs</to-view-id>
     </navigation-case>
 </navigation-rule>
 
 <navigation-rule>
     <display-name>formRelbugs</display-name>
     <from-view-id>/formRelbugs.jsp</from-view-id>
     <navigation-case>
         <from-outcome>sucesso_ins</from-outcome>
         <to-view-id>/mostrarRelbugs.jsp</to-view-id>
     </navigation-case>
 </navigation-rule>
 
 <navigation-rule>
     <display-name>menu</display-name>
     <from-view-id>/menu.jsp</from-view-id>
     <navigation-case>
         <from-outcome>novo</from-outcome>
         <to-view-id>/formRelbugs.jsp</to-view-id>
     </navigation-case>
 </navigation-rule>
 
 <navigation-rule>
     <display-name>atualizarRelbugs</display-name>
     <from-view-id>atuRelbugs.jsp</from-view-id>
     <navigation-case>
         <from-outcome>sucesso_atu</from-outcome>
         <to-view-id>/mostrarRelbugs.jsp</to-view-id>
     </navigation-case>
 </navigation-rule>

 <navigation-rule>
    
    <display-name>mostrarRelbugs</display-name>
    <from-view-id>/mostrarRelbugs.jsp</from-view-id>
    
    <navigation-case>
        <from-outcome>sucesso_exc</from-outcome>
        <to-view-id>/mostrarRelbugs.jsp</to-view-id>
    </navigation-case>
    
 </navigation-rule>    

 <navigation-rule>
    <navigation-case>
        <from-outcome>mostrar</from-outcome>
        <to-view-id>/mostrarRelbugs.jsp</to-view-id>
     </navigation-case> 
 </navigation-rule>
<!--- teste de Pesquisar Cliente-->  
 <navigation-rule>
    <navigation-case>
        <from-outcome>buscar</from-outcome>
        <to-view-id>/buscaCliente.jsp</to-view-id>
     </navigation-case>  
 </navigation-rule>
 <!--- Mostrar pagina de Pesquisa de Cliente--> 
 <navigation-rule>
    <navigation-case>
        <from-outcome>pesquisado</from-outcome>
        <to-view-id>/mostrarClientesPesquisado.jsp</to-view-id>
     </navigation-case> 
 </navigation-rule>
<!--- FIM TESTE--> 


<navigation-rule>
    <display-name>mostrarRelbugs</display-name>
    <from-view-id>/mostrarRelbugs.jsp</from-view-id>
   <navigation-case>
       <from-outcome>novo</from-outcome>
       <to-view-id>/formRelbugs.jsp</to-view-id>
   </navigation-case>
</navigation-rule>
</faces-config>
g4j

Parece tudo ok com teu código! Consegue debugar a aplicação pra ver se o método getBuscarCliente retorna a lista realmente?

L

Nao entendi onde vc chama os metodos de busca para popular o table?
E que action eh esta?

&lt;h:commandButton value="Consultar" action="pesquisado"/&gt;
diegocrs

Esse action que é mostrado é para se reconhecido dentro do arquivo faces-config.xml
entendeu…

E Ja consegui resolver!

Obrigado a todos!

Criado 5 de março de 2009
Ultima resposta 6 de mar. de 2009
Respostas 7
Participantes 3