如何在DataTable上设置默认选择?

时间:2014-03-11 12:22:10

标签: java jquery jsf primefaces datatable

我有一个Java应用程序,我正在使用Hibernate,Primefaces,JSF,Jquery,Twitterbootstrap和Spring。

我的应用程序中有很多 DataTables

我希望 DataTable 有一个默认的选定项目。

主要提供任何方式吗? 这就是现在的样子:

enter image description here

这是我想要的: enter image description here

这是 DataTable

        <!-- Tabela -->
        <p:dataTable 
                     id="dataTableListaCliente"
                     var="cliente" 
                     value="#{clienteBean.lista}" 
                     paginator="true"
                     widgetVar="clientesTable"
                     selection="#{clienteBean.cliente}" 
                     selectionMode="single"
                     filteredValue="#{clienteBean.lista}"
                     style="width: 1100px;"
                     rowsPerPageTemplate="6,10,15,20"   
                     rowKey="#{cliente.id}"
                     paginatorPosition="bottom" 
                     emptyMessage="Nenhum registro encontrado"
                     paginatorTemplate="{CurrentPageReport}  {FirstPageLink} 
                                        {PreviousPageLink} {PageLinks} 
                                        {NextPageLink} {LastPageLink} 
                                        {RowsPerPageDropdown}"
                     rows="6">

           <!-- Duplo click em um registro da tabela -->


          <f:facet name="header">  
            <p:outputPanel>  
              <h:outputText value="Pesquisa Geral:" />  
              <p:inputText id="globalFilter"
                           onkeyup="clientesTable.filter()"
                           style="width:500px" />  
            </p:outputPanel>  
          </f:facet>  

           <p:ajax event="rowDblselect"
                oncomplete="document.getElementById('formLista:buttonSelecionar').click();" />

            <p:column 
                      sortBy="#{cliente.id}"
                      filterBy="#{cliente.id}"
                      filterMatchMode="contains"
                      style="width: 20px;"
                      headerText="Id"
                      >
                #{cliente.id}
            </p:column>

            <p:column
                      sortBy="#{cliente.nome}"
                      filterBy="#{cliente.nome}"
                      filterMatchMode="contains"
                      headerText="Nome">
                #{cliente.nome}
            </p:column>

            <p:column
                      sortBy="#{cliente.endereco}"
                      filterBy="#{cliente.endereco}"
                      filterMatchMode="contains"
                      headerText="Endereço"
                      >
                #{cliente.endereco}
            </p:column>

            <p:column filterBy="#{cliente.cidade}"
                      filterMatchMode="contains"
                      headerText="Cidade">
                #{cliente.cidade}
            </p:column>

            <p:column filterBy="#{cliente.CNPJ}"
                      filterMatchMode="contains"
                      headerText="CNPJ">
                #{cliente.CNPJ}
            </p:column>

            <p:column filterBy="#{cliente.CPF}"
                      filterMatchMode="contains"
                      headerText="CPF">
                #{cliente.CPF}
            </p:column>

            <p:column filterBy="#{cliente.inscricaoEstadual}"
                      filterMatchMode="contains"
                      headerText="Inscrição">
                #{cliente.inscricaoEstadual}
            </p:column>


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

1 个答案:

答案 0 :(得分:2)

只需将保留所选内容的bean值#{clienteBean.cliente}设置为第一行(Set selected row from backing bean in primefaces datatable)的值。