Note that there are some explanatory texts on larger screens.

plurals
  1. POPrimefaces dataTable with checkbox not work
    primarykey
    data
    text
    <p>I am using Primefaces 4.0 with jsf2.2.</p> <p>When I use dataTable with checkbox, it won't send back any record whenever I select records.</p> <p>It supposed to send back the record once I click the checkbox.</p> <p>I remove extra stuff and make my code simple to test it:</p> <p>There is a polling printing selected items every second, so that I can check is there something sent back. </p> <p>And after doing this, I found there's nothing sent back. Here's my code:</p> <p>Page:</p> <pre><code>&lt;h:head&gt; &lt;title&gt;System Monitor&lt;/title&gt; &lt;/h:head&gt; &lt;h:body&gt; &lt;h:form&gt; &lt;p:poll interval="1" listener="#{indexBean.printSelect()}"/&gt; &lt;/h:form&gt; &lt;h:form&gt; &lt;p:dataTable id='data' var="proc" value="#{indexBean.procStatus}" rowKey="#{proc.pid}" selection="#{indexBean.selectedProcs}"&gt; &lt;p:column&gt; &lt;f:facet name='header'&gt; &lt;h:outputText value='Process Name'/&gt; &lt;/f:facet&gt; &lt;h:outputText styleClass="outputCell" id="pname" value='#{proc.name}'/&gt; &lt;/p:column&gt; &lt;p:column selectionMode="multiple"/&gt; &lt;/p:dataTable&gt; &lt;/h:form&gt; &lt;/h:body&gt; </code></pre> <p>Backing Bean:</p> <pre><code>@ManagedBean(name = "indexBean") @ViewScoped public class indexBean implements Serializable { private ProcStatDataModel procStatus; private SingleProcess[] selectedProcs; @PostConstruct public void loadProcStat() { List&lt;SingleProcess&gt; temp = new ArrayList&lt;&gt;(); temp.add(new SingleProcess("test1")); temp.add(new SingleProcess("test2")); temp.add(new SingleProcess("test3")); procStatus = new ProcStatDataModel(temp); } public void printSelect() { if (selectedProcs != null) { String str = ""; for (SingleProcess sp : selectedProcs) { str += sp.getName() + "_"; } System.out.print(str); } else { System.out.println("selectedProcs is null"); } } public ProcStatDataModel getProcStatus() { return procStatus; } public SingleProcess[] getSelectedProcs() { return selectedProcs; } public void setSelectedProcs(SingleProcess[] selectedProcs) { this.selectedProcs = selectedProcs; } } </code></pre> <p>I've tried attaching <code>rowCheckListener</code> like <a href="https://stackoverflow.com/questions/12650546/checkbox-datatable-primefaces-doesnt-working">this</a> before but in vain.</p> <p>Also, I tried adding <code>f:view contentType="text/html"</code> like <a href="https://stackoverflow.com/questions/5569502/primefaces-datatable-selectionmode-multiple-not-working-with-mojarra">this</a> and it was not help.</p> <p>It's weird because I do the same thing with the case of <a href="http://www.primefaces.org/showcase/ui/datatableRowSelectionRadioCheckbox.jsf" rel="nofollow noreferrer">primefaces show case</a> and it acts as I think. So I think this approach is OK, there should be something wrong in my code.</p> <p>Any help is appreciated. Thanks in advance.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload