Meu modal só está excluindo o primeiro item da tabela. Não importa se eu seleciono outro, ele exclui somente o primeiro. Acho q o meu commandbutton não está executando nada, e o modal recebe o meu primeiro objeto setado na tabela.
Preciso de ajuda. O modal abre e executa, as vezes dá null. Estou usando o modal do Bootstrap e JSF.
<html lang="pt-br"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:c="http://xmlns.jcp.org/jsp/jstl/core"
xmlns:stella="http://stella.caelum.com.br/faces2">
<div class="portlet-body">
<h:form id="tabelaProjetoForm" prependId="false">
<input type="hidden" value="#{empresaCtrl.listaProjetosEmpLog()}" />
<table id="sample_3" class="table table-striped table-bordered table-hover dt-responsive" width="100%" cellspacing="0">
<thead>
<tr>
<th class="all">Título</th>
<th class="min-phone-l">Descrição</th>
<th class="min-tablet">Palavras-chaves</th>
<th class="desktop">Ações</th>
</tr>
</thead>
<tbody>
<ui:repeat value="#{empresaCtrl.emprojetos}" var="emp" id="loopProjetoParticipa" varStatus="status">
<tr>
<td>#{emp.tituloProjeto}</td>
<td>#{emp.descricaoProjeto}</td>
<td>#{emp.palavrasChaves}</td>
<td>
<h:commandButton class="btn btn-primary btn-sm" action="#{empresaCtrl.paginaEdProjeto(emp)}" value="EDITAR" />
<h:commandButton class="btn btn-danger btn-sm" actionListener="#{projetoCtrl.detalhes(emp)}" value="EXCLUIR" update="static">
<f:ajax render="@all"/>
<f:setPropertyActionListener value="#{projeto}" target="#{projetoCtrl.projeto}"/>
<f:passThroughAttribute name="data-toggle" value="modal"></f:passThroughAttribute>
<f:passThroughAttribute name="data-target" value="#static"></f:passThroughAttribute>
</h:commandButton>
</td>
</tr>
</ui:repeat>
</tbody>
</table>
</h:form>
<!-- static -->
<div id="static" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="static" aria-hidden="true" data-backdrop="static" data-keyboard="false">
<h:form id="formModelExcluir" prependId="false">
<div class="modal-body">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<p>Deseja realmente excluir o projeto?</p>
<h:outputText value="Título:" />
<h:inputText value="#{projetoCtrl.projeto.tituloProjeto}"
styleClass="clean-inputText" style="margin-top:-10px" />
</div>
<div class="modal-footer">
<button type="button" data-dismiss="modal" class="btn btn-outline dark">Cancelar operação</button>
<h:commandButton class="btn btn-danger" value="Sim, excluir55" update="tabelaProjetoForm:sample_3" actionListener="#{projetoCtrl.excluir(projetoCtrl.projeto)}">
</h:commandButton>
</div>
</h:form>
</div>
<!-- static -->
</div>
Meus Beans e métodos envolvidos:
@Controller(value="empresaCtrl")
@ViewScoped
public class EmpresaController implements Serializable {
public List<Projeto> listaProjetosEmpLog() throws ServiceException{
Empresa empres = new Empresa();
empres = empresaLogada();
emprojetos = projService.buscarProjetosEmp(empres.getLogin());
return emprojetos;
}
@Controller(value="projetoCtrl")
public class ProjetoController implements Serializable {
public void detalhes(Projeto projeto){
this.projeto = projeto;
}
public void excluir(Projeto projeto){
projetoService.excluir(projeto);
RequestContext context = RequestContext.getCurrentInstance();
context.update("tabelaProjetoForm");
context.update("tabelaProjetoForm:tabelaProjeto");
FacesMessage mensagem = new FacesMessage(FacesMessage.SEVERITY_INFO,"Excluido com Sucesso!",null);
FacesContext.getCurrentInstance().addMessage(null, mensagem);
}
Resumindo, preciso setar o objeto selecionado na tabela de maneira correta. Pois está funcionando com apenas o primeiro.
Desde já meu muito obrigado!
