I can not make the LIST page work in JSF

0

I have the following code that I'm developing with JAVA JSF, primefaces, postgre, cdi, tomcat:

BUSCARBEAN

package controller;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.faces.view.ViewScoped;
import javax.inject.Named;

import model.basica.RegraExcecao;
import model.basica.Usuario;
import model.fachada.Fachada;

@SuppressWarnings("serial")
@Named("buscaUsuario")
@ViewScoped
public class BuscaUsuarioBean implements Serializable {

private List<Usuario> usuarios = new ArrayList<Usuario>();

@PostConstruct
public void init() {
    try {
        Fachada fachada = new Fachada();
        usuarios = fachada.listarUsuario();
    } catch (RegraExcecao e) {
        e.printStackTrace();
    }
}

public List<Usuario> getUsuarios() {
    try {
        Fachada fachada = new Fachada();
        usuarios = fachada.listarUsuario();
    } catch (RegraExcecao e) {
        e.printStackTrace();
    }
    return usuarios;
}

public void setUsuarios(List<Usuario> usuarios) {
    this.usuarios = usuarios;
    }
}

list_user.xhtml

<?xml version="1.0" encoding="ISO-8859-1" ?>
<!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:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui">

<h:head>

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Lista de Usuarios</title>

</h:head>

<h:body>
<h:form id="form">
    <p:messages id="messages" showDetail="true" />
    <p:panelGrid columns="2" cellpadding="6">

    <p:dataTable var="usuario" value="#{buscaUsuario.init}">
        <p:column headerText="Id">
            <h:outputText value="#{usuario.id}" />
        </p:column>

        <p:column headerText="Nome">
            <h:outputText value="#{usuario.nome}" />
        </p:column>

        <p:column headerText="Login">
            <h:outputText value="#{usuario.login}" />
        </p:column>

        <p:column headerText="Senha">
            <h:outputText value="#{usuario.senha}" />
        </p:column>

        <p:column headerText="Data de Cadastro do Usuário">
            <h:outputText value="#{usuario.dataCadastro}" />
        </p:column>

        <p:column headerText="Data de Alteração do Usuário">
            <h:outputText value="#{usuario.dataAlteracao}" />
        </p:column>

        <p:column headerText="Último acesso do usuário">
            <h:outputText value="#{usuario.ultimoLogin}" />
        </p:column>
    </p:dataTable>

    </p:panelGrid>
</h:form>
</h:body>
</html>

I have already tested in a main test class if the data entered in the database is coming back and it is.

I made a

List<Usuario> usuarios = new ArrayList<>();
fachada.listarUsuario();

and shows that they are coming back.

Would anyone know what I'm doing wrong?

    
asked by anonymous 10.07.2018 / 21:03

2 answers

1

I got it !!! = DDD

The problem was that in another ManagedBean I had a list (), so I guess he could not find it because of that. It was just me referencing it in the xhtml of the list that got it! = D

    
11.07.2018 / 15:09
-1

I think the problem is in value="#{buscaUsuario.init} .

You put in value a method that returns nothing as a response and therefore the data is not shown on the page.

Instead change to value="#{buscaUsuario.usuarios} , so the page will show the items in the list.

    
11.07.2018 / 07:01