数据表行保持选中/突出显示,其中selectionMode =“single”

时间:2012-11-26 07:20:13

标签: jsf datatable primefaces

我一直在运行Primefaces 3.0,没有问题,现在我正在尝试升级到3.4.x - 我尝试过3.4,3.4.1和3.4.2并且这个问题都发生在所有3 - 基本上是为了使用selectionMode =“single”选项的数据表,当我单击一行时,无论我选择了多少其他行,它都会保持选中状态。同时我很确定当我点击行时,没有设置selection =“#{databrowser.selectedData}”变量。该表已完全填充,并且没有2行在所有列中具有完全相同的数据。经过测试,这种情况发生在Chrome和Firefox中。我找不到任何类似的问题 - 想知道是否有其他人有这个问题?

除引用元素外,我使用的是3.0代码:

<p:layoutUnit position="center" resizable="true" header="Data Set Details" styleClass="east_panel_header" >
        <h:form id="tblbrowser">  
            <p:dataTable id="dataTable" emptyMessage="No data sets found." style="width: 100%" var="datlis" resizableColumns="true" value="#{databrowser.selectedDataModel}" widgetVar="dataTable" selection="#{databrowser.selectedData}" selectionMode="single" >  

            <p:ajax event="rowSelect" update=":usercomments:commentsTable, :tblbrowser:dataTable" />

            <f:facet name="header" >
                <p:outputPanel>  
                <h:outputText value="Search all fields " />  
                <p:inputText id="globalFilter" onkeyup="dataTable.filter()"/>  
                </p:outputPanel>  
            </f:facet>  

            <p:column id="owner" filterBy="#{datlis.uname}" headerText="Added By" filterMatchMode="contains" >  
                <h:outputText value="#{datlis.uname}" />  
            </p:column>  

            <p:column id="name" filterBy="#{datlis.name}" headerText="Name" >  
                <h:outputText value="#{datlis.name}" />  
            </p:column>  

            <p:column id="description" filterBy="#{datlis.description}" headerText="Description" filterMatchMode="endsWith" >  
                <h:outputText value="#{datlis.description}" />  
            </p:column> 

            <p:column id="datatype" filterBy="#{datlis.data_type}" headerText="Data Type"  
                    filterOptions="#{databrowser.dataTypeOptions}" filterMatchMode="exact" >  
                <h:outputText value="#{datlis.data_type}" />  
            </p:column>  

            <p:column id="quality" filterBy="#{datlis.quality}" headerText="Source Type"  
                    filterOptions="#{databrowser.qualityOptions}" filterMatchMode="exact" >  
                <h:outputText value="#{datlis.quality}" />  
            </p:column>  

            <p:column id="added" headerText="Date Added" filterMatchMode="endsWith" >  
                <h:outputText value="#{datlis.added}" />  
            </p:column>  

            <p:column headerText="Metadata" style="width:40px" >  
                <p:commandButton id="selectButton" rendered="#{datlis.has_metadata}" icon="ui-icon-circle-arrow-s" title="View" ajax="false" >  
                    <f:param name="filepath" value="#{datlis.filepath}" />   
                    <p:fileDownload value="#{filedownloader.mfile}" /> 
                </p:commandButton>
            </p:column>

            <p:column headerText="Data File(s)" style="width:90px" >  
                <p:commandButton id="selectButton2" rendered="#{datlis.has_datafiles}" icon="ui-icon-circle-arrow-s" title="View" ajax="false" >  
                    <f:param name="datafiles" value="#{datlis.datafiles}" />   
                    <p:fileDownload value="#{filedownloader2.dfile}" /> 
                </p:commandButton>
                <h:outputText value=" " />  
                <h:outputText value="#{datlis.zipsize}" />  
            </p:column>   

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

1 个答案:

答案 0 :(得分:0)

您缺少rowKey属性,该属性应该是每行的唯一标识符。

示例,如果您的selectedData对象具有唯一字段id,则您的dataTable组件应如下所示:

<p:dataTable id="dataTable" rowKey=#{datlis.id}
             value="#{databrowser.selectedDataModel}" var="datlis"
             selection="#{databrowser.selectedData}" selectionMode="single" >

无需更新p:ajax中的同一个表格以查看选择内容,因此您可以从更新目标中移除:tblbrowser:dataTable并且只有:{/ p>

<p:ajax event="rowSelect" update=":usercomments:commentsTable" />
相关问题