无法使用RadioButton在PrimeFaces中选择表行

时间:2017-06-16 02:19:30

标签: jsf primefaces

我正在尝试使用PrimeFaces数据表开发Web应用程序。我很难获得与所选行对应的对象。每当我这样做时,都会选择一个空值。以下是相关代码:

<p:dataTable id="presTable" var="pres" value="#{presBean.presentations}"
  rows="10" scrollable="true" scrollWidth="85%" 
  selection="#{presBean.selectedPres}" rowKey="#{pres.id}" paginator="true" 
  paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}" 
  rowsPerPageTemplate="10,25,100" widgetVar="presTable" filteredValue="#{presBean.filteredPres}" selectionMode="single">

    </p:column>

    <f:facet name="footer">                                                                        
        <p:commandButton id="updateButton" process="presTable" value="Update" action="#{presBean.printSelectedPres()}"/>                                                               
    </f:facet>

</p:dataTable>

Java支持bean:

public Presentation getSelectedPres() {
    System.out.println("Returning selected presentation: " + selectedPres);
    return selectedPres;
}

public void setSelectedPres(Presentation selectedPres) {
    System.out.println("Setting selected presentation to " + selectedPres);
    this.selectedPres = selectedPres;
}

public void printSelectedPres() {
    System.out.println("Printing list of checked presentations:");
    System.out.println(selectedPres);
}

1 个答案:

答案 0 :(得分:0)

使用seletionMode = single

添加列
<p:column selectionMode="single" style="width:16px;text-align:center"/>

您可以在此处找到单选按钮示例:https://www.primefaces.org/showcase/ui/data/datatable/selection.xhtml