0

I have tried to make a print the values of a simple Object (Client). but I do not get the Values. These are my classes.

index.html

Here I'm trying to plot the function AllClient but does not work.

<?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://xmlns.jcp.org/jsf/html"
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
      xmlns:f="http://xmlns.jcp.org/jsf/core">
<h:head>
   <!-- <meta charset="utf-8" name="viewport"
          content="width=device-width, initial-scale=1"
          http-equiv="X-UA-Conpatible"/>-->
    <title>hola</title>
</h:head>
<h:body>

    <h:dataTable value="#{clientBean.AllClients()}" var="client"  border="5">
        <h:column>
            <f:facet name="header">ID</f:facet>
            <h:outputText value=" #{client.id}"></h:outputText>
        </h:column>
        <h:column>
            <f:facet name="header">Nombre</f:facet>
            <h:outputText value=" #{client.name}"></h:outputText>
        </h:column>
    </h:dataTable>
</h:body>
</html>

Here are saved the Objects. in the functions AllClients(), these function gib a List of Objects, but I can not plot then.

ClientBean Datei.

package controller;
import model.Client;
import javax.enterprise.context.RequestScoped;
import javax.inject.Named;
import java.util.ArrayList;
import java.util.List;
//Resive peticiones desde el navegador
@Named
@RequestScoped
public class ClientBean {

    public List<Client>  AllClients(){
        List<Client> listaClientes=new ArrayList<>();

            Client client1 = new Client();
            client1.setName("name");
            client1.setId(5);

            Client client2 = new Client();
            client2.setName("name A");
            client2.setId(6);

            listaClientes.add(client1);
            listaClientes.add(client2);
        return listaClientes;
    }
    public Client  Client(){
        Client client1 = new Client();
        client1.setName("pau");
        client1.setId(5);
        return client1;
    }
}

Here is my Class Client, this class is the model of my Object Client. I think that here is not the problem but I just put here if do you need it.


import javax.persistence.*;

@Entity
@Table(name="model.Client", uniqueConstraints = {
        @UniqueConstraint(columnNames = "ID")})
public class Client {
    @Id
    @Column(name = "ID", unique = true, nullable = false)
    private int id;

    @Column(name = "name")
    private String name;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}

halfer
  • 19,824
  • 17
  • 99
  • 186
  • Out of my area, but see this: https://stackoverflow.com/questions/6928365/jsf-does-not-populate-named-requestscoped-bean-with-submitted-input-values "You're mixing CDI and JSF annotations. You can and should not do that. Use the one or the other." – racraman Jan 14 '20 at 02:03
  • Start on https://jsf.zeef.com or the java-ee titorials. All basic info you need is on there. And please use a translation engine if you have some problems with the english language (appreciate your attempt though). Cheers – Kukeltje Jan 14 '20 at 07:07
  • @racraman: OP is using the right ones (modern cdi) – Kukeltje Jan 14 '20 at 07:08

0 Answers0