2 listsItems fill in one from the other JSF

1

Good afternoon,

I have 2 listItems the first is filled with the values Physical Person and Legal Person and the second is filled with the values DNI, PASSPORT I want at the time of choosing Physical Person in the first one, the second one returns with only the value DNI and deactivated, the code I did is the following:

driver code:

public List<SelectItem> getComboTipoIdentificador() {
        List<SelectItem> li = new ArrayList<SelectItem>();
        if (cliente.getFiguraJuridica().equals(Codificadoras.ATC_FIG_JURIDICA_F)){
            li= this.cargaComboCodificadora(Constantes.TABLA_TIPO_IDEN, true);
        }else{
            li.add(new SelectItem(new Integer(1),"DNI_NIF"));
        }
        return li;
    }

code xhtml:

<n:campo clase="scCampoLista scOcupa1de6" label="#{textAtc['atc.altaCliente.labelFiguraJuridica']}*">
    <h:selectOneMenu id="figuraJuridica" value="#{altaSimplificadaForm.cliente.figuraJuridica}" >
         <f:selectItems value="#{altaSimplificadaForm.comboFiguraJuridica}" />
    </h:selectOneMenu>
</n:campo>
<n:campo clase="scCampoLista scOcupa1de6" label="#{textAtc['atc.altaCliente.lableTipoIdentificacion']}*">
    <h:selectOneMenu id="tipoIdentificacion" value="#{altaSimplificadaForm.cliente.tipoIdentificador}">
        <f:selectItems value="#{altaSimplificadaForm.comboTipoIdentificador}"/>
    </h:selectOneMenu>
</n:campo>

I get the following error: value="# {highSimplifiedForm.comboTypeIdentifier}": Error reading 'comboTypeIdentifier' something is wrong in the getComboTypeIdentifier function?

Thanks for your help.

    
asked by Yassine 23.08.2016 в 14:08
source

1 answer

1

It is not recommended to build your list of SelectItems in the getter of comboTypeIdentifier, the reason is that JSF invokes the getters more than once during the life cycle of the bean (You can read more about it aqui

It would be better to ask if the list is already loaded before building it again and thus save us some problems that may occur:

public List<SelectItem> getItems() {
  if ( this.items == null ) {
     this.items = buildItems();
  }
  return this.items;
}

private List<SelectItem> buildItems() {
     // Logica para construir los items
}

On your problem itself, some ideas:

  • You are assigning altaSimplificadaForm.comboTipoIdentificador to <f:selectItems> so I imagine you have a variable comboTypeIdentifier in the high beanSimplifiedForm; however, in the method getComboTipoIdentificador() you do not assign the items to that variable but to another arrayList li . This in theory should not give problems but in any case it does not make much sense.

  • Does the method cargaComboCodificadora handle exceptions? Maybe some exception is occurring and JSF is not able to detail it.

  • answered by 29.08.2016 в 03:30