0

Essa é minha tela

<?xml version='1.0' encoding='UTF-8' ?>
<!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:h="http://xmlns.jcp.org/jsf/html"
      xmlns:p="http://primefaces.org/ui">
    <h:head>
        <title>Teste</title>
    </h:head>
    <h:body>
        <p:outputLabel value="Nome:"/>
        <h:inputText id="nome" value="#{controle.novo.nome}" />
        <br/>
         <p:outputLabel value="CPF:"/>
         <h:inputText id="cpf" value="#{controle.novo.cpf}"/>
        <br/>
         <p:outputLabel value="RG:"/>
         <h:inputText id="rg" value="#{controle.novo.rg}"/>
    </h:body>
</html>

Classe funcionario

public class Funcionario {    
    private String nome;
    private String Cpf;
    private int Rg;

    public Funcionario(String nome, String Cpf, int Rg) {
        this.nome = nome;
        this.Cpf = Cpf;
        this.Rg = Rg;
    }

    public Funcionario() {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    public String getNome() {
        return nome;
    }

    public void setNome(String nome) {
        this.nome = nome;
    }

    public String getCpf() {
        return Cpf;
    }

    public void setCpf(String Cpf) {
        this.Cpf = Cpf;
    }

    public int getRg() {
        return Rg;
    }

    public void setRg(int Rg) {
        this.Rg = Rg;
    }           
}

Classe FuncionarioDao

public class FuncionarioDao {

    private Conexao Con;

    public FuncionarioDao(){
     Con = new Conexao();
    }      

    public Boolean salvarDados(Funcionario execute){

        try {
            String query = "insert into func (nome,cpf,rg) values(?,?,?)";
            PreparedStatement stmt = Con.getConnection().prepareStatement(query);

            stmt.setString(1, execute.getNome());
            stmt.setString(2, execute.getCpf());
            stmt.setInt(3, execute.getRg());

            stmt.execute();
            Con.getConnection().commit();
            stmt.close();

            return true;
        } catch (SQLException ex) {
            Logger.getLogger(FuncionarioDao.class.getName()).log(Level.SEVERE, null, ex);
        }
        return true;
    }        
}

Classe Controle

@ManagedBean
@SessionScoped
public class Controle implements Serializable{

    private Funcionario novo;

    public Controle(){
        novo = new Funcionario();
    }   

    public boolean inserirFunc(Funcionario novoFun){
        FuncionarioDao dao = new FuncionarioDao();
        dao.salvarDados(novoFun);
        return true;
    }     

    public Funcionario getNovo() {
        return novo;
    }

    public void setNovo(Funcionario novo) {
        this.novo = novo;
    }

}

O erro que estou recebendo é:

Não é possível criar instância para·a classe: br.com.testeControle.Controle.

1 Resposta 1

0

Você está chamando o construtor de Controle, este por sua vez chama o construtor de Funcionario (sem parâmetros), o qual está parametrizado para disparar uma exceção caso seja chamado, portanto seu código sempre vai gerar um erro.

Se você irá utilizar o construtor de Funcionario sem parâmetros deve remover linha contendo esta exceção:

throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.

Você deve fazer log-in para responder a esta pergunta.

Esta não é a resposta que você está procurando? Pesquise outras perguntas com a tag .