-1

i have this entity Cliente, and have a relation OneToMany with Telefonos.

@Entity
public class Cliente implements Serializable {

  @Id
  @GeneratedValue(generator = "uuid")
  @Column(name = "id", unique = true)
  private String id;

  private String nombre;

  private String direccion;

  @ManyToOne(fetch = FetchType.EAGER)
  @JoinColumn(name = "idTipoCliente")
  @NotNull
  private ClienteTipo tipo;

  @OneToMany
  @JoinColumn(name="idCliente", referencedColumnName="id")
  private List<Telefono> telefonos;

    public List<Telefono> getTelefonos() {
       return telefonos;
   }

public void setTelefonos(List<Telefono> telefonos) {
    this.telefonos = telefonos;
}


public Cliente() {
}

public Cliente(String id) {
    this.id = id;
}

public String getId() {
    return id;
}

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

public String getNombre() {
    return nombre;
}

public void setNombre(String nombre) {
    this.nombre = nombre;
}



public String getDireccion() {
    return direccion;
}

public void setDireccion(String direccion) {
    this.direccion = direccion;
}



public ClienteTipo getTipo() {
    return tipo;
}

public void setTipo(ClienteTipo tipo) {
    this.tipo = tipo;
}
}

i get the items in my dataTable like this.

 <html xmlns="http://www.w3.org/1999/xhtml"
          xmlns:h="http://xmlns.jcp.org/jsf/html"
          xmlns:f="http://xmlns.jcp.org/jsf/core"
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets">

    <h:head>
         <title>Catalogo de Clientes</title>
     </h:head>
<h:body>

    <label>Nombre:</label>
    <h:inputText value=""/>
    <h:dataTable value="${clientesView.getClientes()}" var="cliente">
        <h:column> 
            <f:facet name="header">Nombre</f:facet>
           ${cliente.nombre}
        </h:column>
        <h:column>
            <f:facet name="header">Direccion</f:facet>
             ${cliente.direccion}
        </h:column>
        <h:column>
            <f:facet name="header">Tipo Cliente</f:facet>
             ${cliente.tipo.descripcion}
        </h:column>
    </h:dataTable>
</h:body>
</html>

Each Cliente have a list of telefonos, how could i print it in the same column, i tried to create a new h:dataTable into the h:column but doesnt reconoize the list.

  <h:column>
            <f:facet name="header">Telefonos</f:facet>
            <h:dataTable value="${cliente.telefonos}" var="tel">

             <h:column>
                 <f:facet name="hader">Descripcion</f:facet>
                 ${tel.descripcion}
             </h:column>
            </h:dataTable>
             ${cliente.tipo.descripcion}
        </h:column>
Chay
  • 57
  • 2
  • 7

1 Answers1

0

The telephone entity must have the customer id So: You can have a post construct in the bean:

Private List <Telefono> phones; // getters & setters
@PostConstruct
Public void init () {
phones = // dao to get the phone list
}
public String sendPhone (String idClient) {
    for (Phone t: this.getPhones()) {
      If (t.idCliente.equals (idClient)) {
        return t.description // or phone
      }
    }
}

The code xhtml:

<h:dataTable value = "$ {clientsView.getCustomers()}" var = "client">
             <h:column>
                 <f:facet name = "header"> Phone</f:facet>
                $ {clientsView.sendPhone (client.id)}
             </h:column>
</h:datatable>

Note:The telephone must belong to a customer through a relationship

Maicoly Morocho
  • 149
  • 1
  • 14