Error while trying to display the information of an object in a p: dialog /

1

I'm developing a system using JSF, PrimeFaces, JPA, maven and PostgreSQL. I am new to JEE and am having difficulties with using PrimeFaces, so let's get down to the problem:

I have a client list screen and on this screen I would like to be able to view, update or delete a registered client.

For starters I'm trying to display information from a selected client, however, by selecting the object on the screen and clicking the button to display dialog , I'm getting the following exception:

  

Can not convert Client {"here is the selected object's information :)"} of type class model.entity.Customer to class javax.faces.model.ListDataModel

ManagedBean :

@ManagedBean
@SessionScoped
public class ControlerCliente implements Serializable {
    private static final long serialVersionUID = 1L;
    private Cliente cliente;
    private Endereco endereco;
    private ListDataModel<Cliente> selectClientes =null;

 public ControlerCliente() {
        this.endereco = new Endereco();
        this.cliente = new Cliente();
        }
    public List<Cliente> obterClientes() {
        return ClienteModel.getInstanceCliModel().findAllClientesModel();

    }

}

Listing screen:

<?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:p="http://primefaces.org/ui"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:f="http://xmlns.jcp.org/jsf/core">

    <body>

        <ui:composition template="./../templates/template.xhtml">

            <ui:define name="top">
                <ui:include src="/includes/menu.xhtml"/>
            </ui:define>

            <ui:define name="content">
                <h:form>
                    <p:dataTable id="singleCli" var="cliente" value="#{controlerCliente.obterClientes()}" rows="3" rowKey="#{cliente.codigo}"
                                 selection="#{controlerCliente.selectClientes}" selectionMode="single" paginator="true">
                        <f:facet name="header">
                            LISTA DE CLIENTES CADASTRADOS
                        </f:facet>

                        <p:column headerText="CODIGO: ">
                            <h:outputLabel value="#{cliente.codigo}"/>
                        </p:column>
                        <p:column headerText="NOME: " filterBy="#{cliente.nome}">
                            <h:outputText value="#{cliente.nome}"/>
                        </p:column>
                        <p:column headerText="CPF: ">
                            <h:outputText value="#{cliente.cpf}"/>
                        </p:column>
                        <p:column headerText="DATA CADASTRO">
                            <h:outputText value="#{cliente.dataAbertura}"/>
                        </p:column>

                        <p:column headerText="E-MAIL: ">
                            <h:outputText value="#{cliente.email}"/>
                        </p:column>

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

                        <p:column headerText="RUA: ">
                            <h:outputText value="#{cliente.endereco.bairro}"/>
                        </p:column>

                        <p:column headerText="NÚMERO: ">
                            <h:outputText value="#{cliente.endereco.numero}"/>
                        </p:column>
                        <p:column headerText="CEP: ">
                            <h:outputText value="#{cliente.endereco.cep}"/>
                        </p:column>

                        <p:column headerText="OPÇÕES">
                            <p:commandButton icon="ui-icon-trash"/>                            
                        </p:column>
                        <f:facet name="footer">
                            <p:commandButton value="VISUALIZAR" onclick="PF('cliDialog').show();"/>
                        </f:facet>


                    </p:dataTable>
                </h:form>

                <p:dialog id="visuCliente"  header="cliente - view" widgetVar="cliDialog" modal="true" showEffect="fade" hideEffect="fade" resizable="false"
                          draggable="false" >

                    <h:form>
                        <p:panelGrid  columns="2"  >
                            <h:outputText value="CÓDIGO"/>
                            <p:outputLabel value="#{controlerCliente.cliente.codigo}"/>

                            <h:outputText value="CPF"/>
                            <p:outputLabel value="#{controlerCliente.cliente.cpf}"/>

                            <h:outputText value="EMAIL"/>
                            <p:outputLabel value="#{controlerCliente.cliente.email}"/>

                            <h:outputText value="NOME"/>
                            <p:outputLabel value="#{controlerCliente.cliente.nome}"/>

                            <h:outputText value="DATA-CADASTRO"/>
                            <p:outputLabel value="#{cliente.dataAbertura}"/>

                            <h:outputText value="RUA"/>
                            <p:outputLabel value="#{controlerCliente.cliente.endereco.rua}"/>

                            <h:outputText value="BAIRRO"/>
                            <p:outputLabel value="#{controlerCliente.cliente.endereco.cep}"/>

                            <h:outputText value="CIDADE"/>
                            <p:outputLabel value="#{controlerCliente.cliente.endereco.cidade}"/>

                        </p:panelGrid>

                    </h:form>
                </p:dialog>

            </ui:define>


        </ui:composition>

    </body>
</html>
    
asked by anonymous 24.06.2018 / 01:48

1 answer

1

The datatable is with the selectionMode="single" parameter, so you can select only one record from the table. The problem is that you are setting the selected record in a ListDataModel, in: selection="#{controlerCliente.selectClientes}" . Try changing to selection="#{controlerCliente.cliente}" .

    
26.06.2018 / 18:49