0
votes

I'm having a problem with the dataTable multiple selection with checkbox (like the second one: http://primefaces.org/showcase/ui/datatableRowSelectionRadioCheckbox.jsf). When I try to execute a method in my backingBean, the selected items always comes with the right size, but, with the same object. Example: I select in my dataTable three Messages: Message 1, Message 2 and Message 3. When I execute my method in the JSF page my selected items comes like this:

Messages[0] = Message 1
Messages[1] = Message 1
Messages[2] = Message 1

Here is my JSF Page:

<p:dataTable id="mensagensLidas" var="msg" value="#{mensagensBean.msgGrupoModel}" 
paginator="true" rows="10" selection="#{mensagensBean.selectedMsgsGrupo}">

    <p:column selectionMode="multiple" style="width:2%"/>

    <p:column headerText="Titulo:" style="width:49%">  
        #{msg.titulo}  
    </p:column>

    <f:facet name="footer">
        <p:commandButton id="multiViewButton" value="#{msgs.delete}" icon="ui-icon-trash" actionListener="#{mensagensBean.excluirMsgsGrupo}" update=":tabMain" ajax="true"/>
    </f:facet>

</p:dataTable>
2
why selectionMode="multiple" is in column not in datable as here primefaces.org/showcase/ui/datatableRowSelectionMultiple.jsf?Darka
Edited the question, it's like the second example: primefaces.org/showcase/ui/…arielmolina
can you put also code where you print data?Darka

2 Answers

1
votes

Your above code is working fine for me except that I'm using a rowKey.
Try using rowKey attribute in p:dataTable

<p:dataTable id="mensagensLidas" var="msg" value="#{mensagensBean.msgGrupoModel}" 
                paginator="true" rows="10" selection="#{mensagensBean.selectedMsgsGrupo}"
                rowKey="#{msg.titulo}">
....

</p:dataTable>

Using rowKey is must and best practice when you have selection in Datables, it helps to map the selected <tr> to the POJOs that you're filling up with.
Usually its even better if your rowKey is unique propety, you can even put an integer variable in your #{msg} POJO as best practice.

0
votes

I discovered the problem. My DataModel was with the getRowData returning always the same object. I was doing a wrong comparison. Thank you all!