Considering the following entity class:
import java.io.Serializable;
import java.util.List;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
@Entity
@SequenceGenerator(name = "cliente_sequencia", sequenceName = "cliente_sequencia",
allocationSize = 1, initialValue = 1)
public class Cliente implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "cliente_sequencia")
private int id;
private String cpf;
private String nome;
private String email;
private List<String> telefones;
public Cliente(){
}
public Cliente(String cpf, String nome, String email, List<String> telefones) {
this.cpf = cpf;
this.nome = nome;
this.email = email;
this.telefones = telefones;
}
public int getId() {
return id;
}
public String getCpf() {
return cpf;
}
public void setCpf(String cpf) {
this.cpf = cpf;
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public List<String> getTelefones() {
return telefones;
}
public void setTelefones(List<String> telefones) {
this.telefones = telefones;
}
public void addTelefone(String telefone) {
telefones.add(telefone);
}
public void removeTelefone(String telefone) {
telefones.add(telefone);
}
@Override
public String toString() {
return "Cliente{" + "id=" + id + ", cpf=" + cpf + ", nome=" + nome + ", email=" + email + ", telefones=" + telefones + '}';
}
}
Having this driver:
@Named
@RequestScoped
public class Controlador2 implements Serializable{
private Cliente cliente = new Cliente();
@EJB
private ClienteDAO servico = new ClienteDAO();
private List<Cliente> todos = new ArrayList<>();
public String redirecionar(){
return "index.xhtml";
}
public String salvar(){
servico.salvar(cliente);
todos = servico.todos();
return "listaTodos.xhtml";
}
public Cliente getCliente() {
return cliente;
}
public void setCliente(Cliente cliente) {
this.cliente = cliente;
}
public List<Cliente> todos() {
return servico.todos();
}
public void setTodos(List<Cliente> todos) {
this.todos = todos;
}
}
How could I create a form with jsf that had a field where I could insert a list of phones? I've never done anything like that !!