Difficulty to view data in a Vraptor web project

Asked

Viewed 111 times

0

Check my JSP page

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>


    <table>
        <thead>
            <tr>
                <th>Nome</th>
                <th>Descrição</th>
                <th>Preço</th>
            </tr>
        </thead>
        <tbody>
            <c:forEach items="${produtoList}" var="produto">
                <tr>
                    <td>${produto.nome }</td>
                    <td>${produto.descricao }</td>
                    <td>${produto.preco }</td>
                </tr>
            </c:forEach>
        </tbody>
    </table>

</body>
</html>

see how my page turned out

inserir a descrição da imagem aqui

That’s how you’ll come, nothing shows up. My web project is correctly configured for Vraptor, but I think the problem is in these two files below;

Product and the Product Controller

package br.com.fj28.dao;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.Transaction;

import br.com.caelum.vraptor.ioc.Component;
import br.com.fj28.infra.CriadorDeSession;
import br.com.fj28.modelo.Produto;

@Component
public class ProdutoDao {

    private final Session session;

    public ProdutoDao() {
        this.session = CriadorDeSession.getSession();
    }

    public void salva(Produto produto) {

        Transaction tx = session.beginTransaction();
        session.save(produto);
        tx.commit();
    }


    public List<Produto> listaTudo(){
        return this.session.createCriteria(Produto.class).list();
    }

}

///////////////////////////////////////////////////////

package br.com.fj28.controller;

import java.util.List;

import br.com.caelum.vraptor.Resource;
import br.com.fj28.dao.ProdutoDao;
import br.com.fj28.modelo.Produto;

@Resource
public class ProdutosController {

    private final ProdutoDao dao;

    public ProdutosController(ProdutoDao dao){
        this.dao = dao;

    }

    public List<Produto> lista(){
        return dao.listaTudo();
    }

}

could someone give me a suggestion to solve the problem?

I am confirming that there are records in the Mysql database.

  • you imported the jstl library?

  • that was the problem, thank you

  • 1

    for nothing, if you can answer your own question and mark as answered.

1 answer

1

Apparently you forgot to import the JSTL tag lib this way:

<%@ taglib prefix="c"% uri="http://java.sun.com/jsp/jstl/core">
<%@ taglib prefix="fmt"% uri="http://java.sun.com/jsp/jstl/fmt">

PSC: fmt -> if you need formatting

Browser other questions tagged

You are not signed in. Login or sign up in order to post.