Action - h:commandButton - jsf "action não encontra MB"

5 respostas
jetj

Srs.

Tenho uma pagina onde irei buscar atendimentos não respondidos e após busca inserir a resposta.Para busca o h:commandButton encontra o MB normalmente mas, após busca, listadas as ocorrencias o h:commandButton de cada row não contra o MB. Segue codigo …

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%@ taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
<!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">
        <link rel="StyleSheet" type="text/css" href="../style/estilos.css" media="screen" />
        <link type="text/css" href="../css/ui-lightness/jquery-ui-1.7.2.custom.css" rel="stylesheet" />
        <script type="text/javascript" src="../js/jquery-1.3.2.min.js"></script>
        <script type="text/javascript" src="../js/jquery-ui-1.7.2.custom.min.js"></script>
        <script type="text/javascript">
            $(function(){

                // Accordion
                $("#accordion").accordion({ header: "h3" });

                // Tabs
                $('#tabs').tabs();


                // Dialog
                $('#dialog').dialog({
                    autoOpen: false,
                    width: 600,
                    buttons: {
                        "Ok": function() {
                            $(this).dialog("close");
                        },
                        "Cancel": function() {
                            $(this).dialog("close");
                        }
                    }
                });

                // Dialog Link
                $('#dialog_link').click(function(){
                    $('#dialog').dialog('open');
                    return false;
                });

                // Datepicker
                $('#datepicker').datepicker({
                    inline: true
                });

                // Slider
                $('#slider').slider({
                    range: true,
                    values: [17, 67]
                });

                // Progressbar
                $("#progressbar").progressbar({
                    value: 20
                });

                //hover states on the static widgets
                $('#dialog_link, ul#icons li').hover(
                function() { $(this).addClass('ui-state-hover'); },
                function() { $(this).removeClass('ui-state-hover'); }
            );

            });
        </script>
    </head>
    <body class="ui-widget">
        <div class="ui-widget">
            <div class="ui-state-highlight ui-corner-all" style="margin-top: 20px; padding: 0 .7em;">
                <p><span class="ui-icon ui-icon-info" style="float: left; margin-right: .3em;"></span>
                    Cadastro de Respostas
            </div>
        </div>

        <div id="tabs">
            <ul>
                <li><a href="#tabs-1">Busca</a></li>
                <li><a href="#tabs-2">Atualização</a></li>
                <li><a href="#tabs-3">Third</a></li>
            </ul>
            <div id="tabs-1">
                <f:view>
                    <h:form>
                        <fieldset>
                            <legend>Busca por email</legend>
                            <h:panelGrid columns="3" id="inputs">
                                <h:outputLabel for="email" value="Email :"  />
                                <h:inputText id="email" value="#{atendimento.email}" size="60"  required="true"
                                             requiredMessage="Campo e-mail obrigatório!"></h:inputText>
                                <h:message for="email" styleClass="message" ></h:message>
                                <h:commandButton value="Buscar"  action="#{atendimento.pesquisaByEmail}"/>
                                <h:commandButton value="Voltar"  action="#{atendimento.voltar}"/>
                            </h:panelGrid>
                        </h:form>
                      
                     </fieldset>
                </div>
                <div id="tabs-2">

                    <h:form >

                        <fieldset>
                            <legend>Cadastro de dúvida</legend>
                            <h:panelGrid columns="3" id="inputs" >
                                <h:outputLabel for="email" value="Email :"  />
                                <h:inputText id="email" value="#{atendimento.email}" size="40"  required="true"
                                             requiredMessage="Campo e-mail obrigatório!"></h:inputText>
                                <h:message for="email" styleClass="message" ></h:message>

                                <h:outputLabel for="duvida" value="Resposta :"  />
                                <h:inputTextarea  id="duvida" value="#{atendimento.resposta}"
                                                  required="true" requiredMessage="Descreva sua duvida !!!!" styleClass="edit"
                                                  rows="12" cols="50"/>
                                <h:message for="duvida" styleClass="message"></h:message>
                                <h:commandButton value="Atualizar"  action="#{atendimento.CadastraDuvida}" onclick="retornaOk();"/>

                                <h:commandButton value="Voltar"  action="#{atendimento.voltar}"/>
                            </h:panelGrid>
                        </fieldset>
                        <h:messages></h:messages>
                    </h:form>
            </div>
            <div id="tabs-3">
                <h:form>
                            <h:panelGrid>
                                <h:dataTable id="dt1" value="#{atendimento.model}" var="item" rendered="#{atendimento.model.rowCount > 0}">
                                    <f:facet name="header">
                                    </f:facet>
                                    <h:column>
                                        <f:facet name="header">
                                            <h:outputText value="Email"/>
                                        </f:facet>
                                        <h:outputText value="#{atendimento.model.rowData['txEmailVisitante']}"></h:outputText>
                                    </h:column>
                                    <h:column>
                                        <f:facet name="header">
                                            <h:outputText value="Duvida" />
                                        </f:facet>
                                        <h:outputText value="#{atendimento.model.rowData['txDuvida']}" ></h:outputText>
                                    </h:column>

                                    <h:column>
                                        <h:commandButton action="#{atendimento.pesquisaById}" value="Editar">
                                            <f:param name="id" value="#{atendimento.model.rowData['idAtendimento']}"/>
                                        </h:commandButton>
                                        <h:commandButton action="#{projectManager.remove}" value="Remover"  />
                                    </h:column>
                                </h:dataTable>
                            </h:panelGrid>
                        
                        <h:messages></h:messages>
                    </h:form></div>
        </div>
                         </f:view>
    </body>
</html>

MB e métodos:

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package modelo;

import java.awt.event.ActionEvent;
import java.util.Date;
import java.util.List;
import java.util.Map;
import javax.faces.component.UIParameter;
import javax.faces.model.ListDataModel;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import persistencia.TbAtendimento;

/**
 *
 * @author andre
 */
public class Atendimento {

    public String duvida;
    public String email;
    public String resposta;
    public Date dat_registro;
    public Date dat_resposta;
    private int  id;
    private ListDataModel model;

    /**
     * @return the duvida
     */
    public String getDuvida() {
        return duvida;
    }

    /**
     * @param duvida the duvida to set
     */
    public void setDuvida(String duvida) {
        this.duvida = duvida;
    }


    /**
     * @return the email
     */
    public String getEmail() {
        return email;
    }

     public void setEmail(String email) {
        this.email = email;
    }

    /**
     * @return the resposta
     */
    public String getResposta() {
        return resposta;
    }

    /**
     * @param resposta the resposta to set
     */
    public void setResposta(String resposta) {
        this.resposta = resposta;
    }

    /**
     * @return the dat_registro
     */
    public Date getDat_registro() {
        return dat_registro;
    }

    /**
     * @param dat_registro the dat_registro to set
     */
    public void setDat_registro(Date dat_registro) {
        this.dat_registro = dat_registro;
    }

    /**
     * @return the dat_resposta
     */
    public Date getDat_resposta() {
        return dat_resposta;
    }

    /**
     * @param dat_resposta the dat_resposta to set
     */
    public void setDat_resposta(Date dat_resposta) {
        this.dat_resposta = dat_resposta;
    }


    /**
     * @return the model
     */
    public ListDataModel getModel() {
        return model;
    }

    /**
     * @param model the model to set
     */
    public void setModel(ListDataModel model) {
        this.model = model;
    }

    /**
     * @return the id
     */
    public int getId() {
        return id;
    }

    /**
     * @param id the id to set
     */
    public void setId(int id) {
        this.id = id;
    }

   public String  CadastraDuvida(){
   Configuration cfg = new Configuration();
   cfg.configure();//procura hiber.cfg.xml na raiz
   SessionFactory sessionFactory = cfg.buildSessionFactory();

  //obter objeto de sessao
   Session sessaoHib = sessionFactory.openSession();
   //abrindo transacao
   Transaction tx = sessaoHib.beginTransaction();


   //criar objetos transientes
   TbAtendimento at = new TbAtendimento();

   at.setTxEmailVisitante(email);
   at.setTxDuvida(duvida);
    at.setDtRegistro(new Date());

   //tornando os objetos persistentes
      sessaoHib.save(at);

      try{
   tx.commit();
return "Cadastrado com sucesso !!" ;
      }catch(Exception e){
System.out.println(e);
return "Erro ao cadastrar"+e ;
      }
    }


public boolean  pesquisaByEmail(){

 
 Configuration cfg = new Configuration();
cfg.configure();//procura hiber.cfg.xml na raiz
SessionFactory sessionFactory = cfg.buildSessionFactory();
  //obter objeto de sessao
 Session sessaoHib = sessionFactory.openSession();
   //abrindo transacao
  
try{
  List list = sessaoHib.createQuery("from persistencia.TbAtendimento  " +
          "where txResposta = null and txEmailVisitante like '%"+email+"%'").list();
    setModel(new ListDataModel(list));
}catch(Exception e){
    System.out.println(e);
    return false;
}
  sessaoHib.close();
       return  true ;
   
}
public boolean  pesquisaById(){

Configuration cfg = new Configuration();
cfg.configure();//procura hiber.cfg.xml na raiz
SessionFactory sessionFactory = cfg.buildSessionFactory();
  //obter objeto de sessao
 Session sessaoHib = sessionFactory.openSession();
   //abrindo transacao

try{
    Map requestParam = null;
   String parametro = (String) requestParam.get("id");

   List list = sessaoHib.createQuery("from persistencia.TbAtendimento  " +
          "where txResposta = null and idAtendimento like '%"+parametro+"%'").list();
    setModel(new ListDataModel(list));
}catch(Exception e){
    System.out.println(e);
    return false;
}
  sessaoHib.close();
       return  true ;
   }

}

Agradeço qualquer ajuda…

5 Respostas

jeroqueiroz

o MB esta na Seção ou na Requisição?

jetj

Requisição …

atendimento modelo.Atendimento request
jetj

O valor do ID está sendo enviado normalmente no POST…

jeroqueiroz

Muda pra seção so pra verificar.

jetj

Exatamente…Muito Obrigado pela ajuda !!!

Ao mudar o scopo o MB é encontrado normalmente, independente do command !!!

Criado 5 de fevereiro de 2010
Ultima resposta 5 de fev. de 2010
Respostas 5
Participantes 2