Board index JavaServer Faces General Problem with dataTable and dialog

Problem with dataTable and dialog

Components, Ajax Framework, Utilities and More.


Posts: 10
Hi..!! I've a dataTable and one column is used for edit row data...that column has a commandButton that show a dialog when it's clicked.
The problem's that the dialog appear, but it doesn't show data, only inputText empty.
I have been reading the oldest post that the users have been writting here, but the solutions it doesn´t work for me.

This is the code of the table
            <p:dataTable id="clientesTable" paginator="true" value="#{ClienteBean.clienteList}" var="row"
                         rows="10" paginatorPosition="bottom"
                         paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}"
                         emptyMessage="No hay datos cargados..">

                 <p:column>
                     <f:facet name="header">
                         <h:outputText value="Nombre"/>
                     </f:facet>
                     <h:outputText value="#{row.nombre} #{row.apellido}"/>
                 </p:column>
               
                 <p:column>
                     <f:facet name="header">
                         <h:outputText value="Eliminar"/>
                     </f:facet>
                     <p:commandButton styleClass="button_table_size" image="button_delete_icon" onclick="confirmation.show()">
                         <f:setPropertyActionListener value="#{row}" target="#{ClienteBean.selectedCliente}"/>
                     </p:commandButton>
                 </p:column>
                 <p:column>
                     <f:facet name="header">
                         <h:outputText value="Editar"/>
                     </f:facet>
                     <p:commandButton update="datosAEditar" image="button_edit_icon" styleClass="button_table_size"
                                      oncomplete="editDialog.show()">
                         <f:setPropertyActionListener value="#{row}" target="#{ClienteBean.selectedCliente}"/>
                     </p:commandButton>
                 </p:column>
            </p:dataTable>


This is the code of the dialog
            <p:dialog header="Editar Usuario" widgetVar="editDialog" closable="true"
                      showEffect="slide" hideEffect="fold" modal="true">

                <p:outputPanel id="datosAEditar" rendered="#{not empty ClienteBean.selectedCliente}">
                    <h:panelGrid columns="2" >
                        <h:outputText value="Nombre:"/><h:inputText value="#{ClienteBean.selectedCliente.nombre}"/>
                        <h:outputText value="Apellido:"/><h:inputText value="#{ClienteBean.selectedCliente.apellido}"/>
                        <h:outputText value="Dni:"/><h:inputText value="#{ClienteBean.selectedCliente.dni}"/>
                        <h:outputText value="Telefono:"/><h:inputText value="#{ClienteBean.selectedCliente.telefono}"/>
                        <h:outputText value="Mail:"/><h:outputText value="#{ClienteBean.selectedCliente.mail}"/>
                        <h:selectBooleanCheckbox value="#{ClienteBean.selectedCliente.estudiante}"/><h:outputText value="Estudiante?"/>

                        <p:commandButton styleClass="button" value="Aceptar" actionListener="#{ClienteBean.editCliente}"
                                         update="clientesTable, messages" oncomplete="editDialog.hide()"/>
                        <p:commandButton styleClass="button" value="Cancelar" onclick="editDialog.hide()"/>
                    </h:panelGrid>
                </p:outputPanel>

            </p:dialog>

I have treated that the commandButton update the panelGrid directly without the outputpanel, but doesn't work...the output panel was a recomendation of OptimusPrime to an user, but doesn's work for me =(

This is my bean..
@ManagedBean(name="ClienteBean")
@SessionScoped
public class ClienteBean implements Serializable{

    //Atributos
    private Cliente cliente= new Cliente();
    private Cliente selectedCliente= new Cliente();
    private String infoAction="";

    //Constructores
    public ClienteBean(){}

    //Getters y Setters
    public Cliente getCliente() {
        return cliente;
    }

    public void setCliente(Cliente cliente) {
        this.cliente = cliente;
    }

    public Cliente getSelectedCliente() {
        return selectedCliente;
    }

    public void setSelectedCliente(Cliente selectedCliente) {
        this.selectedCliente = selectedCliente;
    }

    public String getInfoAction() {
        return infoAction;
    }

    public void setInfoAction(String infoAction) {
        this.infoAction = infoAction;
    }

    public List<Cliente> getClienteList(){
        List<Cliente> clientes=new ArrayList<Cliente>();
        clientes= GenericDAO.getList(Cliente.class);
        return clientes;
    }


    //Mtodos propios
    public void saveCliente(){
        FacesContext currentContext= FacesContext.getCurrentInstance();

        if (!DataValidator.isEmail(cliente.getMail().trim()))
        {   // Si no es un email valido
            setInfoAction("Por favor ingrese un E-Mail válido.");
            currentContext.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR,"Error", infoAction));
           
        }
        try
        {   // Intentamos guardar el cliente
            Transaction t = GenericDAO.createTransaction();
            GenericDAO.merge(cliente);
            GenericDAO.commit(t);

            //Limpio los datos del cliente para ingresar otro
            clean();
           
            // Si salio todo bien
            setInfoAction("Cliente cargado exitosamente.");
            currentContext.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO,"Exito", infoAction));
           
        }
        catch (org.hibernate.exception.ConstraintViolationException e)
        {   // DNI 0 CUIT repetido
            e.printStackTrace();
            setInfoAction("DNI/CUIT repetido.");
            currentContext.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR,"Error", infoAction));
        }
        catch (Exception e)
        {   // Otro error
            e.printStackTrace();
            setInfoAction("Error al tratar de conectarse con el servidor.   \n" +
                     "Por favor, verifique si el servidor esta encendido   \n" +
                     "o si existen problemas con la red.");
            currentContext.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_FATAL,"Error", infoAction));
        }
    }

    public void clean(){
        cliente=new Cliente();
    }

    public void deleteSelectedCliente(ActionEvent evt){       
        Transaction t= GenericDAO.createTransaction();
        GenericDAO.delete(selectedCliente);
        t.commit();

        FacesContext context= FacesContext.getCurrentInstance();
        infoAction="El cliente se borro satisfactoriamente.";
        context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Exito: ", infoAction));
    }

    public void editCliente(ActionEvent evt){
        Transaction t= GenericDAO.createTransaction();
        GenericDAO.saveOrUpdate(selectedCliente);
        t.commit();

        FacesContext context= FacesContext.getCurrentInstance();
        infoAction="El cliente se edito satisfactoriamente.";
        context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Exito: ", infoAction));
    }
}


Delete a row works fine with the confirmDialog...


Posts: 315
Location: Brazil
Hello,
take a look here: viewtopic.php?f=3&t=6600&p=27261#p27261

its the way ive been using dialogs and i have no bugs.

i hope it helps.
Att,

--

Rafael Mauricio Pestano
Graduando em Ciência da Computação - UFRGS


Primefaces 4.x, PF-Ext 1.x, Glassfish 4.x, JBossAS 7.1.2, Tomee, Mojarra: 2.1.x, CODI 1.0.5 on Ubuntu 12.04
Conventions Framework
Blog
@realpestano


Posts: 93
maybe you should try to update a component which is alredy rendered, because if the element isn't rendered is not going to be updated.
I would try to put rendered expression in the panelgrid and let outputpanel always rendered, in order to commandbutton update takes effect!


Posts: 53
you can either add this to your datatable definition
onRowSelectComplete="confirmation.show()" onRowSelectUpdate="datosEditar"
This will negate the need for pressing a button. Check out the Instant Selection Mode under DataTable in the showcase.

If you still need the commandButton to show the dialog, then you will need to add this to your commandButton in the datatable
<p:commandButton styleClass="button_table_size" image="button_delete_icon" onclick="confirmation.show()" update="datosEditar">
      <f:setPropertyActionListener value="#{row}" target="#{ClienteBean.selectedCliente}"/>
</p:commandButton>
PF-2.2.1 || Mojarra 2.0.3-FCS || Eclipse 3.6.1 (Helios) || Weblogic 11gR1


Return to General