Problem with dataTable and dialog

Components, Ajax Framework, Utilities and More.
Post Reply
Jimmy87_XFaces
Posts: 10
Joined: 21 Dec 2010, 08:02

05 Jan 2011, 06:13

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

Code: Select all

            <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

Code: Select all

            <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..

Code: Select all

@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...

User avatar
kwintesencja
Posts: 316
Joined: 08 Feb 2010, 20:33
Location: Brazil

05 Jan 2011, 12:42

Hello,
take a look here: http://primefaces.prime.com.tr/forum/vi ... 261#p27261

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

i hope it helps.
Att,

--

Rafael Mauricio Pestano


Primefaces 5.x + JavaEE7(Glassfish 4.x and Wildfly 8)
Conventions Framework
Blog
@realpestano

dmantil
Posts: 93
Joined: 14 Jul 2010, 22:30

06 Jan 2011, 02:59

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!

inxsible
Posts: 53
Joined: 07 Dec 2010, 21:30

06 Jan 2011, 21:42

you can either add this to your datatable definition

Code: Select all

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

Code: Select all

<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

Post Reply
  • Information
  • Who is online

    Users browsing this forum: Bing [Bot], Yahoo [Bot] and 1 guest