Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I made a few changes and it worked. Not sure, which one is the solution.</p> <p>1) Changed all the ' to ".</p> <p>2) Datatable's <code>value="#{indexBean.procStatus}"</code> is wrong i think. I changed it to the name of the ArrayList inside the class. So, it became <code>value="#{indexBean.procStatus.mylist}"</code></p> <p>3) Added an ajax listener, like the one you mentioned in the question. <code>&lt;p:ajax event="rowSelectCheckbox" listener="#{indexBean.check}" /&gt;</code>.</p> <p>4) Added <code>pid</code> to the constructor which will be our rowKey.</p> <p>5) Now, the poll prints the array.</p> <p>Resultin xhtml is as follows:</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.mylist}" rowKey="#{proc.pid}" selection="#{indexBean.selectedProcs}"&gt; &lt;p:ajax event="rowSelectCheckbox" listener="#{indexBean.check}" /&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; &lt;/ui:composition&gt; </code></pre> <p>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;SingleProcess&gt;(); temp.add(new SingleProcess("test1",1)); temp.add(new SingleProcess("test2",2)); temp.add(new SingleProcess("test3",3)); 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; } public void check(SelectEvent event) { System.out.println("in check"); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    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