0
I am building a list in JSF, which uses attributes of two classes (ItemdoPedido and Produto).
Man ManagedBean is class-based ItemdoPedido, then the difficulty is in setting and recovering the class value Produto.
Classes of the model:
public class Produto{
    public int id;
    public String descricao;
    /* getters and setters */
}
public class ItemDoPedido{
    private int id;
    private int quantidade;
    private Produto p;
}
This is my DAO who builds the list and is called in the bean:
public class ItemdoPedidoDAO {    
      public List<ItemDoPedido> MostrarPedidos() {
            Connection con = Conexao.getConnection();
            PreparedStatement stmt = null;
            ResultSet rs = null;
            List<ItemDoPedido> itens = new ArrayList<>();
            try {
                stmt = con.prepareStatement("select p.id as id_pedido, i.qtdade as qtdade, r.descricao as descricao\n"
                        + "from cliente c inner join pedido p on c.id = p.id_cliente\n"
                        + " join item_do_pedido i on p.id = i.id_pedido\n"
                        + " join produto r on i.id_produto = r.id\n"
                        + " where c.cpf = '982139812'"
                        + "");
                rs = stmt.executeQuery();
                while (rs.next()) {
                    ItemDoPedido i = new ItemDoPedido();
                    Produto produto = new Produto();
                    i.setId(rs.getInt("id_pedido"));
                    i.setQuantidade(rs.getInt("qtdade"));
                    i.setP(produto.setDescricao(rs.getString("descricao")));
                    itens.add(i);
               }        
            } catch (SQLException ex) {
                Logger.getLogger(ClienteDAO.class.getName()).log(Level.SEVERE, null, ex);
            } finally {
                Conexao.closeConnection(con, stmt, rs);
            }
            return itens;
        }
    }
The problem is in the class above, in the line:
i.setP(produto.setDescricao(rs.getString("descricao")));
She makes the following mistake:
VOID TYPE NOT ALLOWED HERE
This is my bean, getters and Setter do not appear but are included:
@ManagedBean(name="pedidoMB")
@SessionScoped
public class pedidoMB {
    private ItemDoPedido item;
    private Produto produto;
    private List<ItemDoPedido> itens;
    private ItemdoPedidoDAO iDAO = new ItemdoPedidoDAO();
    public pedidoMB() {
        item = new ItemDoPedido();
        produto = new Produto();
        itens = iDAO.MostrarPedidos(); 
    }
This is the part of my screen that shows the data:
<h:form> 
            <p:panel header="Pedidos">
                <p:link outcome="index" value="Voltar"></p:link>
                <p:dataTable var="item" value="#{pedidoMB.itens}">
                <p:column  headerText="Id">
                    <h:outputText value="#{item.id}" />
                </p:column>
                 <p:column  headerText="Quantidade">
                     <h:outputText value="#{item.quantidade}" />
                </p:column>
                <p:column  headerText="Produto">
                    <h:outputText value="#{item.p.descricao}" />
                </p:column>
            </p:dataTable>
            </p:panel>
        </h:form>
In the end, my idea is to exfil something like this:
ID | QUANTIDADE | PRODUTO
1  |    10      | CADERNO
2  |    20      | CANETA 
						
Thanks a lot man, with your explanation I really understood, tested and worked.
– user125852