0
respostas

Desafio Removendo o Autor

Abaixo o arquivo autor.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 Autor
        </ui:define>

    <ui:define name="conteudo">
        <h:form>
            <fieldset>
                <legend>Dados do Autor</legend>
                <h:panelGrid columns="2">
                    <h:outputLabel value="Nome:" for="nome" />
                    <h:inputText id="nome" value="#{autorBean.autor.nome}" />
                    <h:commandButton value="Gravar" action="#{autorBean.gravar}" />
                </h:panelGrid>
            </fieldset>
            <br />
            <fieldset>
            <h:dataTable value="#{autorBean.autores}" var="autor"
                    id="tabelaAutores">
                    <h:column>
                        <f:facet name="header">Nome</f:facet>
                        <h:outputText value="#{autor.nome}" />
                    </h:column>
                    <h:column>
                        <f:facet name="header">Remover</f:facet>
                        <h:commandLink value="X" action="#{autorBean.remover(autor)}" />
                    </h:column>
                </h:dataTable>
            </fieldset>
        </h:form>
    </ui:define>
</ui:composition>
</html>

Abaixo o método reponsável por excluir o autor, método está dentro da classe AutorBean.java

    public void remover(Autor autor) {
        System.out.println("Removendo o autor " + this.autor.getNome());

        new DAO<Autor>(Autor.class).remove(autor);
    }

Quer mergulhar em tecnologia e aprendizagem?

Receba a newsletter que o nosso CEO escreve pessoalmente, com insights do mercado de trabalho, ciência e desenvolvimento de software