0
votes

I'm starting in primefaces and I'm trying create a editable dialog for my datatable. When I clik in the edit button (footer of datatable), the dialog appears, but dont show the values of the selected row. What's wrong?

my xhtml file:

<?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://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.prime.com.tr/ui"
      xmlns:f="http://java.sun.com/jsf/core">

    <body>

        <ui:composition template="./../WEB-INF/template_sistema.xhtml">

            <ui:define name="content">
                <h:form prependId="false">  

                    <p:dataTable id="dataTable" var="resultadoBanescap" value="#{lstResultados.resultadoBanescap}"  
                                 paginator="true" rows="10"  
                                 paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"  
                                 rowsPerPageTemplate="5,10,15,20"
                                 emptyMessage="Não foram encontradas informações"
                                 selection="#{resultadoBanescap.selecionado}" selectionMode="single">  

                        <p:column id="colunaNumero" 
                                  filterBy="#{resultadoBanescap.rbcnr}" 
                                  sortBy="#{resultadoBanescap.rbcnr}" 
                                  filterMatchMode="contains">  
                            <f:facet name="header">  
                                <h:outputText value="Número" />  
                            </f:facet>  
                            <h:outputText value="#{resultadoBanescap.rbcnr}" />  
                        </p:column>  

                        <p:column id="colunaDia" 
                                  filterBy="#{resultadoBanescap.tbResultadoBanescapPK.rbcdd}" 
                                  sortBy="#{resultadoBanescap.tbResultadoBanescapPK.rbcdd}" 
                                  filterMatchMode="contains">  
                            <f:facet name="header">  
                                <h:outputText value="Dia" />  
                            </f:facet>  
                            <h:outputText value="#{resultadoBanescap.tbResultadoBanescapPK.rbcdd}" />  
                        </p:column>  

                        <p:column id="colunaMes" 
                                  filterBy="#{resultadoBanescap.tbResultadoBanescapPK.rbcmm}" 
                                  sortBy="#{resultadoBanescap.tbResultadoBanescapPK.rbcmm}" 
                                  filterMatchMode="contains">  
                            <f:facet name="header">  
                                <h:outputText value="Mês" />  
                            </f:facet>  
                            <h:outputText value="#{resultadoBanescap.tbResultadoBanescapPK.rbcmm}" />  
                        </p:column>  

                        <p:column id="colunaAno" 
                                  filterBy="#{resultadoBanescap.tbResultadoBanescapPK.rbcaa}" 
                                  sortBy="#{resultadoBanescap.tbResultadoBanescapPK.rbcaa}" 
                                  filterMatchMode="contains">  
                            <f:facet name="header">  
                                <h:outputText value="Ano" />  
                            </f:facet>  
                            <h:outputText value="#{resultadoBanescap.tbResultadoBanescapPK.rbcaa}" />  
                        </p:column> 

                        <f:facet name="footer">  
                            <p:commandButton id="viewButton" 
                                             value="View"  
                                             update=":form:dataTable" 
                                             oncomplete="detalheDialog.show()"
                                             onclick="detalheDialog.show()"/>  
                        </f:facet> 

                    </p:dataTable>  

                    <p:dialog id="dialog" header="Detalhes" widgetVar="detalheDialog" resizable="false"  
                              width="300" showEffect="clip" hideEffect="clip" modal="true" appendToBody="true">  

                        <h:form id="frmUpdate">
                            <h:panelGrid id="display" columns="2" cellpadding="4">  
                                <h:outputText value="Número:" />  
                                <h:inputText value="#{lstResultados.selecionado.rbcnr}" />  

                                <h:outputText value="Dia:" />  
                                <h:inputText value="#{lstResultados.selecionado.tbResultadoBanescapPK.rbcdd}" />  

                                <h:outputText value="Mês:" />  
                                <h:inputText value="#{lstResultados.selecionado.tbResultadoBanescapPK.rbcmm}" />  

                                <h:outputText value="Ano:" />  
                                <h:inputText value="#{lstResultados.selecionado.tbResultadoBanescapPK.rbcaa}" />  
                            </h:panelGrid>  
                        </h:form>
                    </p:dialog>  

                </h:form>  
            </ui:define>

        </ui:composition>

    </body>
</html>

my bean file:

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.banestes.ui.bean;

import br.com.banestes.domain.TbResultadoBanescap;
import br.com.banestes.domain.controller.TbResultadoBanescapJpaController;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;

/**
 *
 * @author 030072182
 */
@RequestScoped
@ManagedBean(name = "lstResultados")
public class ListResultados {

    private List<TbResultadoBanescap> resultadoBanescap;
    private TbResultadoBanescap selecionado;

    public ListResultados() {
        TbResultadoBanescapJpaController ctrl = new TbResultadoBanescapJpaController();
        resultadoBanescap = ctrl.findTbResultadoBanescapEntities();
    }

    public List<TbResultadoBanescap> getResultadoBanescap()
    {
        return resultadoBanescap;
    }

    public TbResultadoBanescap getSelecionado() {
        return selecionado;
    }

    public void setSelecionado(TbResultadoBanescap selecionado) {
        this.selecionado = selecionado;
    }


}

Another question is: is possible create one form in another xhtml and use he in the dialog?

1

1 Answers

0
votes

A few things:

  1. The selected row is not shown in the dialog because the dialog is not updated when the button in your footer is clicked. Your update should be update=":form:dataTable :dialog".
  2. Unless you're doing something with the data on the datatable (I don't see it in your code), you should remove :form:dataTable from your update as well.
  3. In your <p:dataTable>, you are putting the selected data into resultadoBanescap.selecionado. However, in your dialog, you're reading data from lstResultados.selecionado. Check the logic.
  4. You should bring your dialog out of the first form.
  5. Yes, it's possible to create a form in another xhtml file and then use <ui:include> to add it to the dialog.