表在 PrimeFaces 中使用选择模式 = "single"时消失



我有一个commandButton

<p:commandButton value="#{bundle.add}" icon="ui-icon-plus"
   actionListener="#{faPurMB.setFAInfoToTable}"
   style="width:100px;"
   update=":messageGrowl, fsFaInfo, tblAssetList" process="@this, fsFaInfo">
      <p:resetInput target="fsFaInfo" />
</p:commandButton>

和一个dataTable

<p:dataTable id="tblAssetList" value="#{faPurMB.faInfoList}" 
   selectionMode="single"
   var="faList" rowIndexVar="rowSn" scrollable="true" rows="10"
   paginator="true" rowsPerPageTemplate="10,20,50,100" >
</p:dataTable>

当我省略selectionMode="single"时,数据添加得很好。但是,当我包含它时,单击add后该行就消失了。

我的代码有什么问题?

您需要在表组件中设置rowKey属性。例如:

<p:dataTable id="tblAssetList" 
             value="#{faPurMB.faInfoList}" 
             selectionMode="single" 
             var="faList" 
             rowKey="#{faList.id}" ...>

最新更新