0
I am doing a program that registers and relates a customer to a credit card. I am using JSF and Primefaces. It is not necessary to use the Database, so I am storing the data in a same Arraylist.
Basically, when creating a new card I need to show all registered customers so I can select which customer that card will be for.
In the Card Registration screen, in addition to the data to be registered, I put one where shows the results of an Arraylist with the name of all registered customers. The problem is that when I try to create the card with a particular registered customer gives this error here:
I tried to use some converters too, but unsuccessfully and am not sure if this is the problem. Below are some snippets of my code.
Cartaobean class:
public class CartaoBean implements Serializable {
/**
*
*/
private static final long serialVersionUID = -8764412118399727943L;
private Cartao cartao;
private ArrayList<Cartao> cartoes;
private Boolean mostrarPainel;
private Cliente titular;
public CartaoBean() {
this.mostrarPainel = true;
this.cartao = new Cartao();
this.cartoes = new ArrayList<Cartao>();
}
public void cadastrar() {
this.cartoes.add(this.cartao);
this.cartao = new Cartao();
FacesMessage m = new FacesMessage();
m.setSummary("Cartão cadastrado com sucesso!");
m.setSeverity(FacesMessage.SEVERITY_INFO);
/**
* Colocando a mensagem na lista
*/
FacesContext.getCurrentInstance().addMessage(null, m);
}
public Cartao getCartao() {
return cartao;
}
public void setCartao(Cartao cartao) {
this.cartao = cartao;
}
public ArrayList<Cartao> getCartoes() {
return cartoes;
}
public void setCartoes(ArrayList<Cartao> cartoes) {
this.cartoes = cartoes;
}
public Boolean getMostrarPainel() {
return mostrarPainel;
}
public void setMostrarPainel(Boolean mostrarPainel) {
this.mostrarPainel = mostrarPainel;
}
public Cliente getTitular() {
return titular;
}
public void setTitular(Cliente titular) {
this.titular = titular;
}
}
Class Card
public class Cartao implements Serializable {
private static final long serialVersionUID = -4746760068026694731L;
@NotBlank
private String numero;
@NotNull
private double creditoInicial;
@NotNull
private Cliente titular;
public Cartao() {
}
public Cartao(String numero, double creditoInicial) {
this.numero = numero;
this.creditoInicial = creditoInicial;
}
public String getNumero() {
return numero;
}
public void setNumero(String numero) {
this.numero = numero;
}
public Cliente getTitular() {
if (titular == null) titular = new Cliente();
return titular;
}
public void setTitular(Cliente titular) {
this.titular = titular;
}
public double getCreditoInicial() {
return creditoInicial;
}
public void setCreditoInicial(double creditoInicial) {
this.creditoInicial = creditoInicial;
}
}
The xhtml of the register
<h:body>
<h:form>
<p:growl globalOnly="true" />
<p:panel header="Cadastro de Cartão" toggleable="true" closable="true" rendered="#{CartaoBean.cartao.numero}" />
<h:panelGrid>
<p:outputLabel for="n1" value="Cliente"/>
<p:selectOneMenu id="n1" value="#{clienteBean.cliente.cartao}">
<f:selectItems value="#{clienteBean.clientes}" var="cliente" itemLabel="#{cliente.nome}" />
</p:selectOneMenu>
<p:message for="n1" />
<p:outputLabel for="n2" value="Crédito Inicial"/>
<p:inputText id="n2" value="#{cartaoBean.cartao.creditoInicial}"/>
<p:message for="n2" />
<f:facet name="footer">
<p:commandButton update="@form" action="#{cartaoBean.cadastrar}" value="Gerar Cartão de Crédito"/>
</f:facet>
</h:panelGrid>
</h:form>