Problem to convert with composite key in jsf, selecttonemenu

0

I'm doing a selectOneMenu where the itemvalue will be a compound key. Which will be separated by hyphen. However at the time of sending, the method getasobject is called several times, sending all items from my selectonemenu and not just the selected one.

    @FacesConverter(value = "conversorProd")
public class ConversorProdutoDB implements Converter {

    @Override
    public Object getAsObject(FacesContext facesContext, UIComponent uiComponent, String value) {
        if (value != null && !value.isEmpty()) {
            try {
                String[] split = value.split("-"); //assumindo que será separado (idProduto - idGradeSelecionada)

                if (split.length > 1) {
                    GradeProduto gradeProd = PadraoDAO.carregar(GradeProduto.class, Long.valueOf(split[1]));
                    Produto prodComGrade = gradeProd.getProd();
                    prodComGrade.setGradeSelecionada(gradeProd);
                    return prodComGrade;
                } else {
                    return (Produto) PadraoDAO.carregar(Produto.class, Long.valueOf(split[0]));
                }
            } catch (ExceptionBancoDeDados ex) {
                Logger.getLogger(ConversorProdutoDB.class.getName() + "-Erro ao executar conversor de produto").log(Level.SEVERE, null, ex);
            }
        }
        return "";
    }

    @Override
    public String getAsString(FacesContext facesContext, UIComponent uiComponent, Object value) {

            return value != null ? value.toString() : "";

    }
}


          <p:selectOneMenu value="#{transferenciaEstoqueMB.transferenciaDet.transProdOrigem.prod}"
                                     filter="true" filterMatchMode="contains"
                                     converter="conversorProd"
                                     id="slcProd"
                                     >
                        <f:selectItem itemLabel="Selecione" noSelectionOption="true"/>
                        <f:selectItems value="#{transferenciaEstoqueMB.listProduto}"
                                       var='p'
                                       itemLabel="#{p.cod}-#{p.descricao}"
                                       itemValue="#{p.idComposta}"/>
                        <p:ajax listener="#{transferenciaEstoqueMB.onChangeProd()}"
                                process="@this"  update="@(.transProd)"/>
                    </p:selectOneMenu>
    
asked by anonymous 29.11.2017 / 17:14

0 answers