Solucionado (ver solução)
Solucionado
(ver solução)
1
resposta

Dúvida no Ex. 7 da Aula 5 - Controlando o fluxo e resultado com Result

Oi gente!

O método lista() devolve uma lista vazia, sem produtos, após fazer a requisição!

Ainda não entendi porquê!

Aqui está o método lista:

@Get
    public void listaEmXml() {
        EntityManager em = JPAUtil.criaEntityManager();
        ProdutoDao dao = new ProdutoDao(em);
        result.use(Results.xml()).from(dao.lista()).serialize();
    }

E a lista.jsp:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Lista de Produtos</title>
</head>
<link rel="stylesheet" type="text/css" href="../bootstrap/css/bootstrap.css">
<link rel="stylesheet" type="text/css" href="../base.css"/>
<body>
<h3>Lista de Produtos</h3>
<table class="table table-stripped table-bordered table-hover">
    <thead>
        <tr>
        <th>Nome</th>
        <th>Valor</th>
        <th>Quantidade</th>
        <th>Remover</th>
       <th><a href="<c:url value='/produto/formulario'/>">Adicionar mais produtos!</a><br/></th>
       <th>
               <a href="<c:url value='/produto/listaEmXml'/>">Lista em XML</a>
       </th>

        </tr>
    </thead>

    <tbody>
        <c:forEach items="${produtoList}" var="produto">
            <tr>
                <td>${produto.nome}</td>
                <td>${produto.valor}</td>
                <td>${produto.quantidade}</td>
                <td>
                  <a href="<c:url value='/produto/remove?produto.id=${produto.id}'/>">Remover</a>
                </td>
            </tr>
        </c:forEach>
    </tbody>
</table>
    <c:if test="${not empty mensagem }">
        <div class="alert alert-success">${mensagem}</div>
    </c:if>
</body>
1 resposta
solução!

Oi Cremildo, tudo bem?

Esse problema é o mesmo que foi descrito aqui: https://www.alura.com.br/course/desenvolvimento-web-com-vraptor-4/discussions/672442 ?

Respondi lá. Caso não seja o mesmo problema vamos interagindo aqui também. :)

Abraço.

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