Bom dia,
Estou com um problema. Quando eu tento chamar o método remover através do meu livro.xhtml , não acontece ocorre nenhuma ação.
livro.xhtml
<?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://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets">
<ui:composition template="/_template.xhtml">
<ui:define name="titulo">
Novo Livro
</ui:define>
<ui:define name="conteudo">
<h:form id="cadastroLivros">
<h:messages style="color:red" id="messages" />
<fieldset>
<legend>Dados do Livro</legend>
<h:panelGrid columns="2">
<h:outputLabel value="Titulo:" for="titulo" />
<h:inputText id="titulo" value="#{livroMB.livro.titulo}"
required="true" requiredMessage="titulo obrigatorio"
validatorMessage="titulo nao pode ser superior a 40 caracteres">
<f:validateLength maximum="40" />
<f:ajax event="blur" render="messages" />
</h:inputText>
<h:outputLabel value="ISBN:" for="isbn" />
<h:inputText id="isbn" value="#{livroMB.livro.isbn}"
validator="#{livroMB.comecaComDigitoUm}">
<f:ajax event="keyup" render="messages" />
</h:inputText>
<h:outputLabel value="Preço:" for="preco" />
<h:inputText id="preco" value="#{livroMB.livro.preco}">
<f:validateDoubleRange minimum="1.0" maximum="1000.0" />
</h:inputText>
<h:outputLabel value="Data de Lançamento:" for="dataLancamento" />
<h:inputText id="dataLancamento"
value="#{livroMB.livro.dataLancamento.time}">
<f:convertDateTime pattern="dd/MM/yyyy HH:mm" />
</h:inputText>
</h:panelGrid>
</fieldset>
<fieldset>
<legend>Dados do Autor</legend>
<h:outputLabel value="Selecione Autor: " for="autor" />
<h:selectOneMenu value="#{livroMB.autorId}" id="autor">
<f:selectItems value="#{livroMB.autores}" var="autor"
itemLabel="#{autor.nome}" itemValue="#{autor.id}" />
</h:selectOneMenu>
<h:commandButton value="Gravar Autor" action="#{livroMB.gravarAutor}">
<f:ajax execute="autor" render="tabelaAutores" />
</h:commandButton>
<br />
<h:commandLink value="Cadastrar novo autor"
action="#{livroMB.formAutor}" immediate="true" />
<h:dataTable value="#{livroMB.autoresDoLivro}" var="autor"
id="tabelaAutores">
<h:column>
<h:outputText value="#{autor.nome}" />
</h:column>
</h:dataTable>
</fieldset>
<h:commandButton value="Gravar" action="#{livroMB.gravar}">
<f:ajax execute="@form" render="@form :formListas:tabelaLivros" />
</h:commandButton>
</h:form>
<!-- LISTAGEM DE LIVROS -->
<h:form id="formListas">
<h:dataTable value="#{livroMB.livros}" var="livro" id="tabelaLivros">
<h:column>
<f:facet name="header">Título</f:facet>
<h:outputText value="#{livro.titulo}" />
</h:column>
<h:column>
<f:facet name="header">ISBN</f:facet>
<h:outputText value="#{livro.isbn}" />
</h:column>
<h:column>
<f:facet name="header">Preço</f:facet>
<h:outputText value="#{livro.preco}">
<f:convertNumber type="currency" pattern="R$ #0.00"
currencySymbol="R$" locale="pt_BR" />
</h:outputText>
</h:column>
<h:column>
<f:facet name="header">Data</f:facet>
<h:outputText value="#{livro.dataLancamento.time}">
<f:convertDateTime pattern="dd/MM/yyyy HH:mm" />
</h:outputText>
</h:column>
<h:column>
<f:facet name="header">Remover</f:facet>
<h:commandLink value="Remover" action="#{livroMB.remover(livro)}">
</h:commandLink>
</h:column>
</h:dataTable>
</h:form>
</ui:define>
<ui:define name="texto">
Cadastro de Livros
</ui:define>
</ui:composition>
</html>
método remover livroMB (o método gravar está funcionando)
public void gravar() {
System.out.println("Gravando livro " + this.livro.getTitulo());
if (livro.getAutores().isEmpty()) {
// throw new RuntimeException("Livro deve ter pelo menos um Autor.");
FacesContext.getCurrentInstance().addMessage("autor", new FacesMessage("Livro deve ter pelo menos um autor"));
}
new DAO<Livro>(Livro.class).adiciona(this.livro);
this.livro = new Livro();
}
public void remover(Livro livro) {
System.out.println("Removendo Livro" + livro.getTitulo());
new DAO<Livro>(Livro.class).remove(livro);
}
Eu mudei meu CommandLink para CommandButton e funcionou corretamente. Qual o motivo?