I am doing a program that registers and relates a customer to a credit card. I'm using JSF and PrimeFaces. It is not necessary to use the Database, so I am storing the data in an ArrayList myself.
Basically, when creating a new card I need to show all the registered clients so that I can select which customer the card will be.
On the Card Registration screen, in addition to the data to be registered, I placed one where it shows the results of an ArrayList with the name of all the registered clients. The problem is that when I try to create the card with a certain registered customer it gives this error here:
I'vetriedusingsomeconverterstoo,buttonoavailandI'mnotsureifthat'stheproblem.Belowaresomeexcerptsfrommycode.
TarjetaBeanclass:
publicclassCartaoBeanimplementsSerializable{/****/privatestaticfinallongserialVersionUID=-8764412118399727943L;privateCartaocartao;privateArrayList<Cartao>cartoes;privateBooleanmostrarPainel;privateClientetitular;publicCartaoBean(){this.mostrarPainel=true;this.cartao=newCartao();this.cartoes=newArrayList<Cartao>();}publicvoidcadastrar(){this.cartoes.add(this.cartao);this.cartao=newCartao();FacesMessagem=newFacesMessage();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;
}
}
Card Class
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 registration xhtml
<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>