Problema com JSF e HIBERNATE (BUSCA)

2 respostas
M

Pessoal

Estou tendo problema para implantar o sistema de busca usando JSP, JSF e Hibernate segue abaixo:

pacote LivrariaDAO

public List consultarTitulos (String titulo){
            session = ConnectionLivrariaFactory.getInstance();
            Query query = session.createQuery("from Livros l where l.titulo like :titulo");
            List list = query.setString("titulo", "%"+titulo+"%").list();
            return list;
        }

--------------------------------------------------------------------------------------------------------------------------
pacote meupacote.dao.InterfaceLivrosDAO

public abstract List consultarTitulos(String titulo);

------------------------------------------------------------------------------------------------------------------------------
pacote meupacote.controller.LivrosController

public String getKeysearch(){
       return keysearch;
   }

   public void setKeysearch(String keysearch){
       this.keysearch = keysearch;
   }


public DataModel getBuscaLivros(){
       InterfaceLivrosDAO idao = new LivrariaDAO();
       model =
               new ListDataModel(idao.consultarTitulos(keysearch));
       return model;
   }

----------------------------------------------------------------------------------------------------

menu.jsp

<f:view>
             <h:form id="buscar">
                 <h:panelGrid columns="2">
                     <f:facet name="header">
                         <h:outputText value="Busca de Livros" />
                     </f:facet>
                     <h:outputText value="Titulo: " />
                     <h:inputText size="30" id="titulo" value = "#{LivrosView.keysearch}" />
                     <%-- METODO QUE CHAMA MEUPACOTE.CONTROLLER --%>
               </h:panelGrid>
                 <h:commandButton value="Buscar" action="buscar"  />
            </h:form>
</f:view>
---------------------------------------------------------------------------------------------------------- mostrarLivrosPesquisado.jsp
<f:view>
            <h:messages />
            <h1>Livros Encontrados</h1>
            <h:form>
                <h:dataTable value='#{livrosView.BuscarLivro}'
                         var='item' border="1"
                         cellpadding="2" cellspacing="0">
                      <h:column>
                         <f:facet name="header">
                             <h:outputText value="ISBN" />
                        </f:facet>
                     </h:column>
                    <h:column>
                        <f:facet name="header">
                            <h:outputText value="Título" />
                        </f:facet>
                    <h:outputText value="#{item.titulo}"/>
                  </h:column>
                 <h:column>
                    <f:facet name="header">
                        <h:outputText value="Publicacao em" />
                    </f:facet>
                    <h:outputText value="#{item.publicacao}"/>
                </h:column>

                <h:column>
                    <f:facet name="header">
                        <h:outputText value="Excluir Livros" />
                    </f:facet>
                </h:column>
           </h:dataTable>
            <h:commandLink action="#{livrosView.novoLivro}"
                           value="Cadastrar novo livro" />
    </h:form>
        </f:view>
    </body>
</html>
------------------------------------------------------------------------------------------------------------------------

faces-config

<faces-config>

<!--- O Bean LivrosController -->
<managed-bean>
    <managed-bean-name>livrosView</managed-bean-name>
    <managed-bean-class>
        meupacote.controller.LivrosController
   </managed-bean-class>
   <managed-bean-scope>session</managed-bean-scope>
   </managed-bean>

  

  
<!-- Cadastro de novo livro -->
 <navigation-rule>
       <display-name>formLivros</display-name>
       <from-view-id>/formLivros.jsp</from-view-id>
       <navigation-case>
           <from-outcome>sucesso_ins</from-outcome>
           <to-view-id>/mostrarLivros.jsp</to-view-id>
       </navigation-case>
   </navigation-rule>

   <!-- Chamada ao formulario de cadastro de livro -->
 <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>/formLivros.jsp</to-view-id>
       </navigation-case>
   </navigation-rule>

<!--Sucesso da exclusão do Livro -->
<navigation-rule>
       <display-name>mostraLivros</display-name>
       <from-view-id>/mostrarLivros.jsp</from-view-id>
       <navigation-case>
           <from-outcome>sucesso_exc</from-outcome>
           <to-view-id>/mostrarLivros.jsp</to-view-id>
       </navigation-case>
   </navigation-rule>


   <!-- Mostrando livro pesquisado -->
 <navigation-rule>
     <navigation-case>
           <from-outcome>buscar</from-outcome>
           <to-view-id>/mostrarLivrosPesquisado.jsp</to-view-id>
      </navigation-case>
   </navigation-rule>

  
</faces-config>

------------------------------------------------------------------------------------------------------

e apresenta esse erro

type Exception report

message

descriptionThe server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: Target Unreachable, identifier 'LivrosView' resolved to null

root cause

javax.el.PropertyNotFoundException: Target Unreachable, identifier 'LivrosView' resolved to null

note The full stack traces of the exception and its root causes are available in the GlassFish Server Open Source Edition 3.0.1 logs.

Obrigado

2 Respostas

Hebert_Coelho

Olá, seja bem vindo ao GUJ.

  1. Edita seu post, e coloca seu código entre as tags [ code] [ /code] (sem espaço entre os []). Fica mais fácil de ler.
  2. Vc está instanciando seu LivrosView? Pois a mensagem é que ele está nulo. ‘LivrosView’ resolved to null
M

Olá sim estou instanciando livrosView, esta no faces-config.xml
onde esta apontando pelo controller, veja os códigos

Obrigado

Criado 4 de setembro de 2010
Ultima resposta 4 de set. de 2010
Respostas 2
Participantes 2