Good afternoon everyone, I am working on a practice project to increase my skills in JAVA EE, the fact is that I am doing a billing system, using JSF, JPA and PrimeFaces, I have a billing page and within this I have a page that takes the client code of a client and using ajax I execute a method to find the information of this. this is a portion of the invoice code.xhtml
<h:panelGrid id="gridBuscarDatosCliente" columns="4">
<p:outputLabel value="Codigo del cliente" style="font-weight: bold"/>
<p:inputText value="#{facturaBean.cliente.codigoCliente}" size="12">
<p:ajax event="keyup" listener="#{facturaBean.agregarDatosCliente()}"
update=":formularioFactura:gridDatosCliente"/>
</p:inputText>
<p:commandButton value="..." oncomplete="PF('dialogoClientes').show();"
update=":formularioFactura:dlgClientes"/>
<p:outputLabel value="Fecha" style="font-weight: bold"/>
</h:panelGrid>
This is the section that I intend to update every time the client's code is typed in the input:
<p:separator/>
<h:panelGrid id="gridDatosCliente">
<p:outputLabel value="Nombre: " style="font-weight: bold"/>
<p:outputLabel id="lblnombreCliente" value="#{facturaBean.cliente.nombre} #{facturaBean.cliente.apellido}"
style="font-weight: bold"/>
<p:outputLabel value="Direccion: N/A" style="font-weight: bold"/>
<p:outputLabel/>
</h:panelGrid>
and this is myBean bill
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.bean;
import com.pojo.Cliente;
import com.pojo.Factura;
import com.servicios.ClienteFacadeLocal;
import com.servicios.FacturaFacadeLocal;
import com.servicios.VendedorFacadeLocal;
import javax.ejb.EJB;
import javax.inject.Named;
import javax.enterprise.context.RequestScoped;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
/**
*
* @author Ana Sofia
*/
@Named(value = "facturaBean")
@RequestScoped
public class FacturaBean {
@EJB
private ClienteFacadeLocal clienteFacade;
@EJB
private FacturaFacadeLocal facturaFacade;
//Este cliente es la llave foranea
private Cliente cliente;
private Factura factura;
public FacturaBean() {
cliente = new Cliente();
}
public ClienteFacadeLocal getClienteFacade() {
return clienteFacade;
}
public void setClienteFacade(ClienteFacadeLocal clienteFacade) {
this.clienteFacade = clienteFacade;
}
public Cliente getCliente() {
return cliente;
}
public void setCliente(Cliente cliente) {
this.cliente = cliente;
}
public Factura getFactura() {
return factura;
}
public void setFactura(Factura factura) {
this.factura = factura;
}
public void agregarDatosCliente(){
factura.setCodigoCliente(clienteFacade.find(cliente.getCodigoCliente()));
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Correcto", "Datos del cliente agregado"));
}
}
What do you recommend me to do? Thanks in advance.