Refresh dialog form without closing it

2

How can I do to update my form dialog without closing it?

In other words, I need to get the address by the zip code, and I'll throw it on the form, but I can not. Here is the code I'm using.:

View: customer registration

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://xmlns.jcp.org/jsf/core">

    <body>

        <ui:composition template="./../template.xhtml">
            <ui:define name="content">

                <p:growl id="msgs" showDetail="true"/>
                <h:form>
                    <p:commandButton id="btnUsuarioCreate" update=":formCreate" oncomplete="PF('dialogUsuarioCreate').show()" title="Criar" value="Novo Cliente" icon="icon-novo"/>
                </h:form>

                <h:form id="formDataTable">  
                    <p:dataTable id="cars" var="cliente" value="#{clientesBean.clientes}"
                                 paginator="true" rows="10"  paginatorPosition="bottom"
                                 paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"> 
                        <f:facet name="header">  
                            Listando Clientes  
                        </f:facet>       

                        <p:column headerText="Id">  
                            <h:outputText value="#{cliente.idCliente}" />  
                        </p:column>  

                        <p:column headerText="Cpf">   
                            <h:outputText value="#{cliente.cpf}" />  
                        </p:column>  

                        <p:column headerText="Nome:">  
                            <h:outputText value="#{cliente.nome}" />  
                        </p:column>  

                        <p:column headerText="Endereco:">  
                            <h:outputText value="#{cliente.endereco}" />  
                        </p:column>  
                        <p:column headerText="Bairro:">  
                            <h:outputText value="#{cliente.bairro}" />  
                        </p:column>  
                        <p:column headerText="Telefone:">  
                            <h:outputText value="#{cliente.telefone1}" />  
                        </p:column>  
                        <p:column headerText="Celular:">  
                            <h:outputText value="#{cliente.celular1}" />  
                        </p:column>  
                        <p:column headerText="Data Aniversario:">  
                            <h:outputText value="#{cliente.dataAniversario}" />  
                        </p:column>  

                        <p:column style="width:4%">  
                            <p:commandButton id="btnUpdate" update=":formUpdate" oncomplete="PF('dialogUsuarioUpdate').show()" title="Modificar" icon="icon-update">
                                <f:setPropertyActionListener value="#{cliente}" target="#{clientesBean.selectedclientes}" />                                                               
                            </p:commandButton>
                        </p:column>
                        <p:column style="width:4%">
                            <p:commandButton id="btnDelete" update=":formDelete" oncomplete="PF('dialogUsuarioDelete').show()" title="Deletar" icon="icon-delete">
                                <f:setPropertyActionListener value="#{cliente}" target="#{clientesBean.selectedclientes}" />                                                               
                            </p:commandButton>
                        </p:column>

                    </p:dataTable>  
                </h:form>
                <h:form id="formCreate" >
                    <p:dialog header="Cadastrar Cliente" widgetVar="dialogUsuarioCreate" id="dlgUsuarioCreate"
                              modal="true"> 
                        <h:panelGrid id="display" columns="2" cellpadding="4"> 
                            <p:tabView>
                                <p:tab title="Dados Pessoais">
                                    <h:panelGrid id="aba1" columns="2" cellpadding="4"> 
                                        <h:outputText value="CPF:" />  
                                        <p:inputMask mask="999.999.999-99" size="12" value="#{clientesBean.selectedclientes.cpf}"/>
                                        <h:outputText value="RG:" />  
                                        <p:inputText value="#{clientesBean.selectedclientes.rg}" size="12" />  
                                        <h:outputText value="Nome:" />  
                                        <p:inputText value="#{clientesBean.selectedclientes.nome}" size="60"/>
                                        <h:outputText value="Data Aniversario:" />  
                                        <p:inputMask value="#{clientesBean.selectedclientes.dataAniversario}" mask="99/99/9999"/>
                                        <h:outputText value="Status:" />  
                                        <p:selectOneMenu value="#{clientesBean.selectedclientes.status}">  
                                            <f:selectItem itemLabel="Ativado" itemValue="1" />  
                                            <f:selectItem itemLabel="Inativo" itemValue="0" />
                                        </p:selectOneMenu> 
                                    </h:panelGrid>
                                </p:tab>
                                <p:tab title="Dados Endereco" id="tab2" >
                                    <p:commandButton value="Pesquisar CEP" icon="ui-icon-search" action="#{user.encontraCEP}" update=":formCreate"/>
                                    <h:panelGrid id="aba2" columns="2" cellpadding="4">
                                        <h:outputText value="CEP:" />
                                        <p:inputMask mask="99999-999" value="#{clientesBean.selectedclientes.cep}" size="12"  placeholder="#{user.cep}"/>  
                                        <h:outputText value="Endereço:" />  
                                        <p:inputText value="#{user.logradouro}" size="60" placeholder="#{user.logradouro}"/>  
                                        <h:outputText value="Bairro:" />  
                                        <p:inputText value="#{clientesBean.selectedclientes.bairro}" size="50" placeholder="#{user.bairro}"/>  
                                        <h:outputText value="Cidade:" />  
                                        <p:inputText value="#{clientesBean.selectedclientes.cidade}" size="50" placeholder="#{user.cidade}"/>  
                                        <h:outputText value="Complemento:" />  
                                        <p:inputText value="#{clientesBean.selectedclientes.complemento}" size="50" placeholder="#{user.estado}"/>  
                                        <h:outputText value="Ponto de referencia:" />  
                                        <p:inputText value="#{clientesBean.selectedclientes.referencia}" size="50" placeholder="#{user.cep}"/>
                                    </h:panelGrid>
                                </p:tab>
                                <p:tab title="Dados Contato">
                                    <h:panelGrid id="aba3" columns="2" cellpadding="4">
                                        <h:outputText value="Telefone 1:" />  
                                        <p:inputMask mask="(999) 999-9999" value="#{clientesBean.selectedclientes.telefone1}" />  
                                        <h:outputText value="Telefone 2:" />  
                                        <p:inputMask mask="(999) 999-9999" value="#{clientesBean.selectedclientes.telefone2}" />  
                                        <h:outputText value="Celular 1:" />  
                                        <p:inputMask mask="(999) 999-9999" value="#{clientesBean.selectedclientes.celular1}" />  
                                        <h:outputText value="Celular 2:" />  
                                        <p:inputMask mask="(999) 999-9999" value="#{clientesBean.selectedclientes.celular2}" />
                                    </h:panelGrid>
                                </p:tab>
                            </p:tabView>
                            <f:facet name="footer">
                                <p:separator/>
                                <p:commandButton id="btnCreateAccept" update=":formDataTable, :msgs" oncomplete="PF('dialogUsuarioCreate').hide()" actionListener="#{clientesBean.btnCreateClientes(actionEvent)}" title="Salvar" value="Salvar" icon="icon-save"/>
                                <p:commandButton id="btnCreateCancel" oncomplete="PF('dialogUsuarioCreate').hide()" title="Cancelar" value="Cancelar" icon="icon-cancel"/>
                            </f:facet>


                        </h:panelGrid> 
                    </p:dialog>  

                </h:form>  

                <h:form id="formUpdate">
                    <p:dialog header="Modificar Usuario" widgetVar="dialogUsuarioUpdate" id="dlgUsuarioUpdate"
                              modal="true"> 

                        <h:panelGrid id="display" columns="2" cellpadding="4">  

                            <h:outputText value="Id:" style="display: none;"/>  
                            <p:inputText value="#{clientesBean.selectedclientes.idCliente}" style="display: none;" />  

                            <p:tabView>
                                <p:tab title="Dados Pessoais">
                                    <h:panelGrid id="aba1" columns="2" cellpadding="4"> 
                                        <h:outputText value="CPF:" />  
                                        <p:inputText value="#{clientesBean.selectedclientes.cpf}" />  
                                        <h:outputText value="RG:" />  
                                        <p:inputText value="#{clientesBean.selectedclientes.rg}" />  
                                        <h:outputText value="Nome:" />  
                                        <p:inputText value="#{clientesBean.selectedclientes.nome}" />
                                        <h:outputText value="Data Aniversario:" />  
                                        <p:inputText value="#{clientesBean.selectedclientes.dataAniversario}" />  
                                        <h:outputText value="Status:" />  
                                        <p:selectOneMenu value="#{clientesBean.selectedclientes.status}">  
                                            <f:selectItem itemLabel="Ativado" itemValue="1" />  
                                            <f:selectItem itemLabel="Inativo" itemValue="0" />
                                        </p:selectOneMenu> 

                                    </h:panelGrid>
                                </p:tab>
                                <p:tab title="Dados Endereco">
                                    <h:panelGrid id="aba2" columns="2" cellpadding="4">
                                        <h:outputText value="CEP:" />  
                                        <p:inputText value="#{clientesBean.selectedclientes.cep}" />  
                                        <h:outputText value="Endereço:" />  
                                        <p:inputText value="#{clientesBean.selectedclientes.endereco}" />  
                                        <h:outputText value="Bairro:" />  
                                        <p:inputText value="#{clientesBean.selectedclientes.bairro}" />  
                                        <h:outputText value="Cidade:" />  
                                        <p:inputText value="#{clientesBean.selectedclientes.cidade}" />  
                                        <h:outputText value="Complemento:" />  
                                        <p:inputText value="#{clientesBean.selectedclientes.complemento}" />  
                                        <h:outputText value="Ponto de referencia:" />  
                                        <p:inputText value="#{clientesBean.selectedclientes.referencia}" />
                                    </h:panelGrid>
                                </p:tab>
                                <p:tab title="Dados Contato">
                                    <h:panelGrid id="aba3" columns="2" cellpadding="4">
                                        <h:outputText value="Telefone 1:" />  
                                        <p:inputText value="#{clientesBean.selectedclientes.telefone1}" />  
                                        <h:outputText value="Telefone 2:" />  
                                        <p:inputText value="#{clientesBean.selectedclientes.telefone2}" />  
                                        <h:outputText value="Celular 1:" />  
                                        <p:inputText value="#{clientesBean.selectedclientes.celular1}" />  
                                        <h:outputText value="Celular 2:" />  
                                        <p:inputText value="#{clientesBean.selectedclientes.celular2}" />
                                    </h:panelGrid>
                                </p:tab>
                            </p:tabView>

                            <f:facet name="footer">
                                <p:separator/>
                                <p:commandButton id="btnUpdateAccept" update=":formDataTable, :msgs" oncomplete="PF('dialogUsuarioUpdate').hide()" actionListener="#{clientesBean.btnUpdateClientes(actionEvent)}" title="Salvar" value="Salvar" icon="icon-save"/>
                                <p:commandButton id="btnUpdateCancel" oncomplete="PF('dialogUsuarioUpdate').hide()" title="Cancelar" value="Cancelar" icon="icon-cancel"/>
                            </f:facet>
                        </h:panelGrid>  
                    </p:dialog>  

                </h:form>  
                <h:form id="formDelete">
                    <p:confirmDialog message="Esta seguro em exclui este registro?"  
                                     header="Excluir Usuario" severity="alert" widgetVar="dialogUsuarioDelete">  
                        <h:inputHidden value="#{clientesBean.selectedclientes.idCliente}" />  
                        <p:commandButton id="btnUpdateAccept" update=":formDataTable, :msgs" oncomplete="PF('dialogUsuarioDelete').hide()" actionListener="#{clientesBean.btnDeleteClientes(actionEvent)}" value="Sim" icon="icon-accept"/>
                        <p:commandButton id="btnUpdateCancel" oncomplete="PF('dialogUsuarioDelete').hide()" value="Cancelar" icon="icon-cancel"/>

                    </p:confirmDialog>
                </h:form>

            </ui:define>

        </ui:composition>

    </body>
</html>

Managed bean buscarCEP :

/*
 * 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 beans;

import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletRequest;
import util.CepWebService;

@ManagedBean(name = "user")
@SessionScoped
public class UserBean {

    public String userName;

    public String outcome() {
        return "index2";
    }

    public String index() {
        return "index2";
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public void execute(String value) {
        // ...
    }

    private static final long serialVersionUID = 1L;

    private String cep = null;

    private String tipoLogradouro;
    private String logradouro;
    private String estado;
    private String cidade;
    private String bairro;

    public void encontraCEP() {
        CepWebService cepWebService = new CepWebService(getCep());

        if (cepWebService.getResultado() == 1) {
            setTipoLogradouro(cepWebService.getTipoLogradouro());
            setLogradouro(cepWebService.getLogradouro());
            setEstado(cepWebService.getEstado());
            setCidade(cepWebService.getCidade());
            setBairro(cepWebService.getBairro());
        } else {

            FacesContext.getCurrentInstance().addMessage(
                    null,
                    new FacesMessage(FacesMessage.SEVERITY_ERROR,
                            "Servidor não está respondendo",
                            "Servidor não está respondendo"));
        }
    }

    public String getCep() {
        return cep;
    }

    public void setCep(String cep) {
        this.cep = cep;
    }

    public String getTipoLogradouro() {
        return tipoLogradouro;
    }

    public void setTipoLogradouro(String tipoLogradouro) {
        this.tipoLogradouro = tipoLogradouro;
    }

    public String getLogradouro() {
        return logradouro;
    }

    public void setLogradouro(String logradouro) {
        this.logradouro = logradouro;
    }

    public String getEstado() {
        return estado;
    }

    public void setEstado(String estado) {
        this.estado = estado;
    }

    public String getCidade() {
        return cidade;
    }

    public void setCidade(String cidade) {
        this.cidade = cidade;
    }

    public String getBairro() {
        return bairro;
    }

    public void setBairro(String bairro) {
        this.bairro = bairro;
    }
}

NowwhenIclickthesearchbuttonthenullzipformanagedBean

publicclassCepWebService{privateStringestado="";
private String cidade = "";
private String bairro = "";
private String tipoLogradouro = "";
private String logradouro = "";

private int resultado = 0;

@SuppressWarnings("rawtypes")
public CepWebService(String cep) {

    try {
        URL url = new URL(
                "http://cep.republicavirtual.com.br/web_cep.php?cep=" + cep
                        + "&formato=xml");

        Document document = getDocumento(url);

        Element root = document.getRootElement();

        for (Iterator i = root.elementIterator(); i.hasNext();) {
            Element element = (Element) i.next();

            if (element.getQualifiedName().equals("uf"))
                setEstado(element.getText());

            if (element.getQualifiedName().equals("cidade"))
                setCidade(element.getText());

            if (element.getQualifiedName().equals("bairro"))
                setBairro(element.getText());

            if (element.getQualifiedName().equals("tipo_logradouro"))
                setTipoLogradouro(element.getText());

            if (element.getQualifiedName().equals("logradouro"))
                setLogradouro(element.getText());

            if (element.getQualifiedName().equals("resultado"))
                setResultado(Integer.parseInt(element.getText()));
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

public Document getDocumento(URL url) throws DocumentException {
    SAXReader reader = new SAXReader();
    Document document = reader.read(url);

    return document;
}

public String getEstado() {
    return estado;
}

public void setEstado(String estado) {
    this.estado = estado;
}

public String getCidade() {
    return cidade;
}

public void setCidade(String cidade) {
    this.cidade = cidade;
}

public String getBairro() {
    return bairro;
}

public void setBairro(String bairro) {
    this.bairro = bairro;
}

public String getTipoLogradouro() {
    return tipoLogradouro;
}

public void setTipoLogradouro(String tipoLogradouro) {
    this.tipoLogradouro = tipoLogradouro;
}

public String getLogradouro() {
    return logradouro;
}

public void setLogradouro(String logradouro) {
    this.logradouro = logradouro;
}

public int getResultado() {
    return resultado;
}

public void setResultado(int resultado) {
    this.resultado = resultado;
}

}

I have not reached the result yet

    
asked by anonymous 21.05.2015 / 19:46

1 answer

2

This has already happened to me. The solution was instead of giving update in <h:form> where <p:dialog> is giving update in the container of data within <p:dialog> .

In your case, you can <h:panelGrid> that is within <p:dialog> .

    
21.05.2015 / 20:05