0
Guys ,is the following... In this project I’m using JSF,Primefaces and I’m still new to programming.. the list screen is displaying the information according to the bank
Only that I wanted to delete these fields that appear on the list screen when selected through the checkbox...
Follow what I’ve done so far:
@ManagedBean
public class ControlerBean implements Serializable {
private List<Funcionario> funcionarios = this.listarDados();
private List<Funcionario> funcionarioSelecionados;
// private PreparedStatement stmte;
public List<Funcionario> getFuncionarios() {
    return funcionarios;
}
public void setFuncionarios(List<Funcionario> funcionarios) {
    this.funcionarios = funcionarios;
}
public List<Funcionario> getFuncionarioSelecionados() {
    return funcionarioSelecionados;
}
public void setFuncionarioSelecionados(List<Funcionario> funcionarioSelecionados) {
    this.funcionarioSelecionados = funcionarioSelecionados;
}
public List<Funcionario> listarDados() {
    //gerencia
    String sqq = "select funcionario.cpf , nome, matricula,diretoria,departamento,divisao, cargo "
            + "from funcionario "
            + "left JOIN dadosprofissionais "
            + "ON dadosprofissionais.cpf = funcionario.cpf";
    List<Funcionario> lista = new ArrayList<Funcionario>();
    try {
        Statement tt = Conexao.getConexao().createStatement();
        //PreparedStatement tt = Conexao.getConexao().prepareStatement(sqq);
        //tt.setString(1, sqq);
        ResultSet resul = tt.executeQuery(sqq);
        while (resul.next()) {
            Funcionario funcionario = new Funcionario();
            funcionario.setCpf(resul.getString("cpf"));
            funcionario.setNome(resul.getString("nome"));
            funcionario.setMatricula(resul.getInt("matricula"));
            funcionario.setDiretoria(resul.getString("diretoria"));
            funcionario.setDepartamento(resul.getString("departamento"));
            funcionario.setDivisao(resul.getString("divisao"));
            funcionario.setCargo(resul.getString("cargo"));
            lista.add(funcionario);
        }
    } catch (SQLException ex) {
        Logger.getLogger(ControlerBean.class.getName()).log(Level.SEVERE, null, ex);
        //Logger.getAnonymousLogger(ListarBean.class.getName()).log(Level.SEVERE, null, ex);
    }
    return lista;
}
public void excluir() {
    DeletarCadastro excluir = new DeletarCadastro();
    excluir.deletarFuncionario(funcionarioSelecionados);
    for (int i = 0; i < funcionarioSelecionados.size(); i++) {
        Funcionario p = funcionarioSelecionados.remove(i);
        if (p.getCpf().equals(p)) {
            funcionarioSelecionados.remove(p);
        }
    }
}
My page where lists... and on it has the check box to delete
<p:commandLink
            process="tabela" action="#{controlerBean.excluir()}"  >                         
            <left>
                <h:graphicImage library="imagens" name="lixo.png" width="30" height="30"/>
            </left>                 
        </p:commandLink>
        <p:dataTable id="tabela" var="funcionario" value="#{controlerBean.listarDados()}" selection="#{controlerBean.funcionarioSelecionados}" rowKey="#{funcionario.cpf}" style="margin-bottom:0">
            <f:facet name="header">
            </f:facet>
            <p:ajax event="rowSelect" />
            <p:column selectionMode="multiple" style="width:16px;text-align:center"/>
            <p:column  filterBy="#{funcionario.cpf}" headerText="CPF" footerText="Grande Recife " filterMatchMode="contains">
                <h:outputText value="#{funcionario.cpf}" />
            </p:column>
            <p:column headerText="Nome">
                <h:outputText value="#{funcionario.nome}" />
            </p:column>
            <p:column headerText="Matricula">
                <h:outputText value="#{funcionario.matricula}"/>
            </p:column>
            <p:column headerText="Diretoria">
                <h:outputText value="#{funcionario.diretoria}"/>
            </p:column>
            <p:column  headerText="Gerencia">
                <h:outputText value="#{funcionario.departamento}"/>
            </p:column>
            <p:column  headerText="Divisao">
                <h:outputText value="#{funcionario.divisao}"/>
            </p:column>
            <p:column  headerText="Cargo">
                <h:outputText value="#{funcionario.cargo}"/>
            </p:column>                              
        </p:dataTable>        
        <br/><br/><br/>
    </h:form>
</ui:define>
Class excluded from the seat
public class DeletarCadastro {
public Boolean deletarFuncionario(Funcionario deletar) {
     Boolean retorno = false;
    String sql = "DELETE FROM funcionario WHERE cpf = ?";
    try {
        PreparedStatement stmt = Conexao.getConexao().prepareStatement(sql);
        stmt.setString(1, deletar.getCpf());
        stmt.executeUpdate();
        stmt.close();
    } catch (SQLException ex) {
        Logger.getLogger(DeletarCadastro.class.getName()).log(Level.SEVERE, null, ex);
    }
    return retorno;
}
}
Method that calls the class deletarCadastro...this method is in my controlerBean
public void excluir(String nome) {
    DeletarCadastro excluir = new DeletarCadastro();
    //excluir.deletarFuncionario(funcionario);
    for (Funcionario func: funcionarios) {
     funcionarios.remove(func);
       excluir.deletarFuncionario((Funcionario) funcionarios);
    }
Only it is not deleting the selected parameters from the list -- Help aew o/
at least give me a light...I don’t know what I do anymore..
– Ricardo Mendes