2017-06-16 8 views
0

PrimeFacesデータテーブルを使用してWebアプリケーションを開発しようとしています。選択した行に対応するオブジェクトを取得するのが難しいです。私がそれを行うたびに、ヌル値が選択されます。ここに関連するコードは次のとおりです。RadioButtonsを使用してPrimeFacesでテーブル行を選択できません

<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); 
} 
+0

'p:dataTable'は' h:form'で囲まれていますか? –

答えて

0

がseletionModeでカラムを追加=単一

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

あなたがここにあるラジオボタンのサンプルを見つけることができます:https://www.primefaces.org/showcase/ui/data/datatable/selection.xhtml

+0

私はh:formを持っていてselectionModeを追加しました。それでもnull値が表示されています。行が表示され、ラジオボタンを選択するとSystem.out.println(selectedPres)にnullが表示されます。 – user7517586

関連する問題