3

I'm using PrimeFaces 5.0.

What I'm trying to do is with the help of the 1p:autocomplete1 look on the BD, returning suggestions and using itemtip show some other information need it, everything seem to work well, the problem is that when I get the data and selected, this data is not setting it on the property...

autocomplete with the itemtip:

<p:row>
    <p:column colspan="10">
        <p:outputLabel value="Orden de Compra "/>
        <p:autoComplete id="itemTip" value="#{c_ordenCompra.encabezado_encontrado}" 
                        completeMethod="#{c_ordenCompra.completarOrdenCpra}"
                        var="orden" itemLabel="#{orden.numdocucv}" itemValue="#{orden.idencacv}" 
                        converter="themeConverter" forceSelection="true">
            <f:facet name="itemtip">
                <h:panelGrid columns="2" cellpadding="3" cellspacing="5">
                    <h:outputText value="Fecha" />
                    <h:outputText value="#{orden.fechadoctocv}" />

                    <h:outputText value="Sucursal" />
                    <h:outputText value="#{orden.tbsucursalesByFkencacvsucurentra.nomsucur}" />

                    <h:outputText value="Proveedor" />
                    <h:outputText value="#{orden.tbpersonasrelaByIdpersorelaprove.nomcompleto}" />
                </h:panelGrid>
            </f:facet>

        </p:autoComplete>
        <p:commandButton value="buscar" actionListener="#{c_ordenCompra.seleccionarorden()}"/>
    </p:column>
</p:row>

Here is the converter I'm trying to use. (I made some test here and everything seems to work.)

public class converterOC implements Converter {
public Object getAsObject(FacesContext fc, UIComponent uic, String value) {
    if (value != null && value.trim().length() > 0) {
        try {
            M_encacv modelo_encacv = new M_encacv();
            Tbencacv encav_encontrado = modelo_encacv.Ordene1CompraEncacv(value);
            return encav_encontrado;
        } catch (NumberFormatException e) {
            throw new ConverterException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Conversion Error", "Not a valid theme."));
        }
    } else {
        return null;
    }
}

public String getAsString(FacesContext fc, UIComponent uic, Object object) {
    if (object != null) {
        return String.valueOf(object);
    } else {
        return null;
    }
}

Entity:

public class Tbencacv implements java.io.Serializable {

private int idencacv;
private Tbbancos tbbancos;
private Tbbodegas tbbodegasByFkencacvbodesalida;
private Tbbodegas tbbodegasByFkencacvbodeentra;
private Tbcajasvta tbcajasvta;
private Tbcajerosvta tbcajerosvta;
private Tbcias tbcias;
private Tbencainven tbencainven;
private Tbpersonasrela tbpersonasrelaByIdpersorelaprove;
private Tbpersonasrela tbpersonasrelaByIdpersorelaemple;
private Tbpersonasrela tbpersonasrelaByIdpersorelacliente;
private Tbsucursales tbsucursalesByFkencacvsucurentra;
private Tbsucursales tbsucursalesByFkencacvsucursalida;
private Tbterminoscv tbterminoscv;
private Tbtiposmovicv tbtiposmovicv;
private Tbvendecobra tbvendecobra;
private Date fechadoctocv;
private String observagralcv;
private String concepcontagralcv;
private Double valortotalcv;
private Double valorivacv;
private Double valorimpuperecv;
private Double valorexencv;
private Double valorgravacv;
private Double valornosujecv;
private Double valorfovialcv;
private Double porcedescuv;
private String procedecv;
private char cpravta;
private Double valorrentacv;
private int numdocucv;
private char autorizadocucv;
private Date fechablc;
private Character aplicalibroiva;
private Double valorefectivo;
private Double valortarjeta;
private Double valorcheque;
private Integer numcheque;
private String numreserva;
private String numbaucher;
private String numaprobacion;
private Character importacion;
private Character sujetoexcluido;
private Character retentercero;
private String direccionenviar;
private String nomclientedocu;
private Double valorcredito;
private Integer codprove;
private String nomvencob;
private Integer codcliente;
private Integer codemple;
private Character movcerrado;
private Character afectaexisten;
private Character docucvimpre;
private Character paraconsu;
private Character parainven;
private Character paracl;
private String nomuser;
private Set<Tbdetacv> tbdetacvs = new HashSet<Tbdetacv>(0);

public Tbencacv() {
}
//all setters and getters

In the same row as the autocomplete I have a commandbutton. It is suppose to print on console one data from the property I had set on the autocomplete, but it shows nothing.

 public void seleccionarorden() {
    System.out.println(getEncabezado_encontrado().getValorivacv());
    System.out.println(Encabezado_encontrado.getValorivacv());
}

I tried everything it comes to my mind, but I ran out of ideas

what it show on the page

This is what the console show. Not even an exception:

what the console show

2 Answers2

3

Thank you for your help.. i get it to work

this is how it worked

EDIT: Converter

@FacesConverter("converterOC")
public class converterOC implements Converter {
    @Override
    public Object getAsObject(FacesContext fc, UIComponent uic, String value) {
        if (value != null && value.trim().length() > 0) {
            try {
                M_encacv modelo_encacv = new M_encacv();
                Tbencacv encav_encontrado = modelo_encacv.Ordene1CompraEncacv(value);
                return encav_encontrado;
            } catch (NumberFormatException e) {
                throw new ConverterException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Conversion Error", "Not a valid theme."));
            }
        } else {
            return null;
        }
    }

    @Override
    public String getAsString(FacesContext fc, UIComponent uic, Object object) {
        if(object != null) {
            return String.valueOf(((Tbencacv) object).getIdencacv());
        }
        else {
            return null;
        }
    }
}

EDIT: Autocomplete (I changed the <p:CommandButton /> for an itemselect event using ajax)

<p:column colspan="10"><p:outputLabel value="Orden de Compra "/>
    <p:autoComplete id="itemTip" value="#{c_ordenCompra.encabezado_encontrado}" 
                    completeMethod="#{c_ordenCompra.completarOrdenCpra}"
                    var="orden" itemLabel="#{orden.numdocucv}" itemValue="#{orden}" 
                    converter="converterOC" forceSelection="true">
        <f:facet name="itemtip">
            <h:panelGrid columns="2" cellpadding="3" cellspacing="5">
                <h:outputText value="Fecha" />
                <h:outputText value="#{orden.fechadoctocv}" />

                <h:outputText value="Sucursal" />
                <h:outputText value="#{orden.tbsucursalesByFkencacvsucurentra.nomsucur}" />

                <h:outputText value="Proveedor" />
                <h:outputText value="#{orden.tbpersonasrelaByIdpersorelaprove.nomcompleto}" />
            </h:panelGrid>
        </f:facet>
        <p:ajax event="itemSelect" listener="#{c_ordenCompra.seleccionarorden}" update="noc,date,acs,acb,soli,prov,ter,nreg,dtdetalles"  /> 

    </p:autoComplete>
1

The attribute itemValue="#{orden.idencacv}" of p:autoComplete refers to property of orden that is Tbencacv object. You should give it as a object.

Change the itemValue="#{orden.idencacv}" of p:autoComplete to itemValue="#{orden}"

Refer 15.10 Creating and Using a Custom Converter from The Java EE Tutorial

శ్రీ
  • 143
  • 10
  • i did it, still not getting the data set... could it be the converter? – Oscar Rene Guerrero Aug 08 '16 at 15:09
  • ensure getter/setter methods are available for the property in ManagedBean and [choose the right bean scope](http://stackoverflow.com/questions/7031885/how-to-choose-the-right-bean-scope) – శ్రీ Aug 08 '16 at 16:56
  • This post may help you [selectonemenu jsf on objects with converter](http://stackoverflow.com/questions/17748706/selectonemenu-jsf-on-objects-with-converter) – శ్రీ Aug 08 '16 at 17:15