How to update a form with ui: repeat without duplicating oc fields in jsf?

2

I have a problem with my ui: repeat components, I want to update and not repeat the components, how?

My form:

<h:body>
    <h:form >
        <h:outputLabel class="col-sm-2 col-sm-2 control-label" value="CEP"  />  
        <p:inputMask mask="99999-999" id="cep"
                     placeholder="#{clienteController.cliente.cep}" 
                     value="#{clienteController.cep}"  
                     maxlength="9" 
                     required="true" 
                     requiredMessage="Campo Obrigatório !"
                     /> 
        <p:spacer width="55" height="10" />
        <h:commandButton  id="Buscar_Dados" value="Buscar Dados" 
                          action="#{clienteController.buscarDadosCEP(clienteController.cep)}" >
            <f:ajax execute="@form"   render="panelCEP"/>
        </h:commandButton>
    </h:form>

    <h:form id="panelCEP" >
        <!--INICIO AUTOPREENCHIMENTO DO ENDERECO-->
        <h:panelGroup  >
            <ui:repeat  id="alterarClienteCEPDados" value="#{clienteController.enderecos}" var="dadosEnderecoAlterar" varStatus="status">
                <h:column >
                    <div class="form-group">
                        <h:outputLabel  value="Logradouro" class="col-sm-2 col-sm-2 control-label" />
                        <div class="col-sm-10">
                            <h:inputText value="#{dadosEnderecoAlterar.logradouro}" 
                                         class="form-control" />
                        </div>
                    </div>

                    <div class="form-group">
                        <h:outputLabel  value="Número" class="col-sm-2 col-sm-2 control-label" />

                    </div>

                    <div class="form-group">
                        <h:outputLabel  value="Bairro" class="col-sm-2 col-sm-2 control-label" />
                        <div class="col-sm-10">
                            <h:inputText value="#{dadosEnderecoAlterar.bairro}" class="form-control"  disabled="true"/>
                        </div>
                    </div>

                    <div class="form-group">
                        <h:outputLabel  value="Cidade" class="col-sm-2 col-sm-2 control-label" />
                        <div class="col-sm-10">
                            <h:inputText value="#{dadosEnderecoAlterar.cidade}" class="form-control" disabled="true" />
                        </div>
                    </div>

                    <div class="form-group">
                        <h:outputLabel  value="Estado" class="col-sm-2 col-sm-2 control-label" />
                        <div class="col-sm-10">
                            <h:inputText value="#{dadosEnderecoAlterar.UF}" class="form-control" disabled="true" />
                        </div>
                    </div>
                </h:column>
            </ui:repeat>
        </h:panelGroup>
    </h:form>
</h:body>

My method with filling the list:

public void buscarDadosCEP(String cep) throws Exception {

    Endereco dadosEndereco = new Endereco();
    cepService.getDadosCep(cep);
    if (cepService.getResultado() == 1) {
        cliente.setBairro(cepService.getBairro());
        cliente.setCidade(cepService.getMunicipio());
        cliente.setLogradouro(cepService.getLogradouro());
        cliente.setCep(cepService.getCep());
        cliente.setEstado(cepService.getUf());
        dadosEndereco.setBairro(cepService.getBairro());
        dadosEndereco.setCidade(cepService.getMunicipio());
        dadosEndereco.setCep(cepService.getCep());

        dadosEndereco.setLogradouro(cepService.getLogradouro());
        dadosEndereco.setUF(cepService.getUf());
        enderecos.add(dadosEndereco);
        enderecos.size();
        setCampoCepAlterar(true);

I put the zip code and click on the auto-fill button, but when I click again it duplicates the fields, how do I not duplicate and update only those specific fields without duplicating them?

    
asked by anonymous 02.11.2016 / 23:12

1 answer

2

I just set a new address array in the method.

endereco = new ArrayList<>():
    
03.11.2016 / 01:49