1
votes

I have a requirement as follows

A datatable with checkbox select option and row select also retain the multi selection,

When the user clicks on the check box the respective rows should selected and at the same time if any row of the datatable is selected by row select event that should retian the exisiting selected item and the current selection also vice versa.

Due to the primefaces frawork limitation I could not achieve this requirement, can any one help me to achieve this requirement

Sample Xhtml :

<p:dataTable id="checkboxDT" var="car" value="#{dtSelectionView.cars6}" selection="#{dtSelectionView.selectedCars}" rowKey="#{car.id}" style="margin-bottom:0">
        <f:facet name="header">
            Checkbox
        </f:facet>
        <p:column selectionMode="multiple" style="width:16px;text-align:center"/>
        <p:column headerText="Id">
            <h:outputText value="#{car.id}" />
        </p:column>
        <p:column headerText="Year">
            <h:outputText value="#{car.year}" />
        </p:column>
        <p:column headerText="Brand">
            <h:outputText value="#{car.brand}" />
        </p:column>
        <p:column headerText="Color">
            <h:outputText value="#{car.color}" />
        </p:column>
        <f:facet name="footer">
            <p:commandButton process="checkboxDT" update=":form:multiCarDetail" icon="ui-icon-search" value="View" oncomplete="PF('multiCarDialog').show()" />
        </f:facet>
    </p:dataTable>

Sample Bean : scope : Group conversational Scope

public void onRowSelect(SelectEvent event) {
    FacesMessage msg = new FacesMessage("Car Selected", ((Car) event.getObject()).getId());
    FacesContext.getCurrentInstance().addMessage(null, msg);
}

public void onRowUnselect(UnselectEvent event) {
    FacesMessage msg = new FacesMessage("Car Unselected", ((Car) event.getObject()).getId());
    FacesContext.getCurrentInstance().addMessage(null, msg);
}

Note :

Please verify the primefaces showcase for default component behaviour

1
Please post your Java code for #{employeeBean.selectedEmployeeList} so we can see it. What scope is the employeeBean?Melloware
Better yet, post a minimal reproducible exampleKukeltje
My EmployeeBean.java is in GroupConversationScope public void rowSelect(Employee employee) { this.selectedEmployeeList.add(employee); } public void rowUnSelect(Employee employee) { this.selectedEmployeeList.remove(employee); }Kannan JB
Please edit your question to include the entire code for EmployeeBean. Also make sure to study this working example: primefaces.org/showcase/ui/data/datatable/selection.xhtml I have no problem with selection so keep debugging and simplifying your use case until you figure it out.Melloware
There is no sample xhtml visible in your question...Kukeltje

1 Answers

2
votes

"Due to the primefaces frawork limitation I could not achieve this requirement, can any one help me to achieve this requirement"

It's not a limitation, it is as designed. With ctrl-click you can add additional rows when clicking on them. But if you want to change this behaviour, the relevant info is in on page 161 of the PrimeFaces 6.2 documentation.

rowSelectMode     new     String     Defines row selection mode for multiple selection.
                                     Valid values are "new", "add" and "checkbox".

So adding

rowSelectMode="add"

to your datatable most likely does the trick.