Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8605777
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:55:28+00:00 2026-06-12T02:55:28+00:00

the checkbox datatable of primefaces library doesn’t work for me, I tried to make

  • 0

the checkbox datatable of primefaces library doesn’t work for me, I tried to make the same code as the showcase of primefaces but when I check some rows and I click on the view button the selectedCars[] contains 0 rows :
here is my xhtml page :

    <?xml version="1.0" encoding="UTF-8"?>
<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core">
    <h:head>
        <title>TODO supply a title</title>
    </h:head>
    <h:body>
        <h:form id="form"> 
            <p:dataTable id="multiCars" var="car" value="#{fortest.mediumCarsModel}" paginator="true" rows="10"  
                         selection="#{fortest.selectedCars}">  

                <f:facet name="header">  
                    Checkbox Based Selection  
                </f:facet>  

                <p:column selectionMode="multiple" style="width:18px" />  

                <p:column headerText="id">  
                    #{car.id}  
                </p:column>  

                <p:column headerText="date envoi">  
                    #{car.dateEnvoi}  
                </p:column>  

                <p:column headerText="decision" >  
                    #{car.decision}  
                </p:column>  

                <f:facet name="footer">  
                    <p:commandButton id="multiViewButton" value="View" icon="ui-icon-search"  
                                     update=":form:displayMulti" oncomplete="multiCarDialog.show()"/>  
                </f:facet>  
            </p:dataTable>  

            <p:dialog id="multiDialog" header="Car Detail" widgetVar="multiCarDialog"  
                      height="300" showEffect="fade" hideEffect="explode">  

                <p:dataList id="displayMulti"  
                            value="#{fortest.selectedCars}" var="selectedCar">  
                    id : #{selectedCar.id}, dateEnvoi #{selectedCar.dateEnvoi}  
                </p:dataList>  

            </p:dialog>  
        </h:form>
    </h:body>
</html>

and here is my managed-Bean :

    @ManagedBean
@SessionScoped
public class fortest implements Serializable {

    private Commande[] selectedCars;
    private dortestDataModel mediumCarsModel; 
    utilisateursHelper uh;
    /**
     * Creates a new instance of fortest
     */
    public fortest() {
        uh = new utilisateursHelper();
        mediumCarsModel = new dortestDataModel(uh.getAllCommandes());

    }

    public void setSelectedCars(Commande[] selectedCars) {
        System.out.println("alors je suis donc la size : "+selectedCars.length);
        this.selectedCars = selectedCars;
    }

    public Commande[] getSelectedCars() {
        return selectedCars;
    }

    public dortestDataModel getMediumCarsModel() {
        return mediumCarsModel;
    }

}

and here is my dataModel :

   public class dortestDataModel extends ListDataModel<Commande> implements SelectableDataModel<Commande> {    

    utilisateursHelper uh;

    public dortestDataModel() {  
    }  

    public dortestDataModel(List<Commande> data) {  
        super(data);  
        uh = new utilisateursHelper();
    }  

    @Override  
    public Commande getRowData(String rowKey) {  
        //In a real app, a more efficient way like a query by rowKey should be implemented to deal with huge data  


        List<Commande> cars = (List<Commande>) uh.getAllCommandes();  

        for(Commande car : cars) {  
            if(car.getId().equals(rowKey))  
                return car;  
        }  

        return null;  
    }  

    @Override  
    public Object getRowKey(Commande car) {  
        return car.getId();  
    }  
}  

do you have any idea, thank you in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T02:55:29+00:00Added an answer on June 12, 2026 at 2:55 am

    you forgot to attach rowCheckListener to your datatable like this

      <p:ajax event="rowSelectCheckbox" listener="#{forTest.check}"   />  
    

    below code is working for me. i am able to see the id and decision on the dialog.

    XHTML:
    i dint implement selectableDataModel, i just used rowKey attribute of datatable, you could use that as well

    <h:form id="form"> 
        <p:dataTable id="multiCars" var="car" value="#{forTest.carList}" paginator="true" rows="10"  
                      rowKey ="#{car.id}" selection="#{forTest.selectedCars}" >  
          <p:ajax event="rowSelectCheckbox" listener="#{forTest.check}"   />  
            <f:facet name="header">  
                Checkbox Based Selection  
            </f:facet>  
    
            <p:column selectionMode="multiple" style="width:18px" />  
    
            <p:column headerText="id">  
                #{car.id}  
            </p:column>  
    
              <p:column headerText="decision" >  
                #{car.decision}  
            </p:column>  
    
            <f:facet name="footer">  
                <p:commandButton id="multiViewButton" value="View" icon="ui-icon-search"  
                                 update=":form:displayMulti" oncomplete="multiCarDialog.show()"/>  
            </f:facet>  
        </p:dataTable>  
    
        <p:dialog id="multiDialog" header="Car Detail" widgetVar="multiCarDialog"  
                  height="300" showEffect="fade" hideEffect="explode">  
    
            <p:dataList id="displayMulti"  
                        value="#{forTest.selectedCars}" var="selectedCar">  
                id : #{selectedCar.id}, dateEnvoi #{selectedCar.decision}  
            </p:dataList>  
    
        </p:dialog>  
    </h:form>
    

    ManagedBean:

    package managedbeans;
    import java.io.Serializable;
    import java.util.ArrayList;
    import java.util.List;
    
    import javax.faces.bean.ManagedBean;
    import javax.faces.bean.SessionScoped;
    import javax.jws.Oneway;
    
    import org.primefaces.event.SelectEvent;
    
    import beans.Car;
    
    
    
        @ManagedBean(name="forTest")
        @SessionScoped
        public class forTest implements Serializable {
             private List<Car> carList = new ArrayList<Car>();
             private Car selectedCars[];
    
            public Car[] getSelectedCars() {
                return selectedCars;
            }
    
            public void setSelectedCars(Car selectedCars[]) {
                this.selectedCars = selectedCars;
            }
    
            public List<Car> getCarList() {
                if(carList.size()==0) {
                    setCarList();
                }
                return carList;
            }
    
            public void setCarList() {
                this.carList.add(new Car(1, "car1"));
                this.carList.add(new Car(2, "car2"));
                this.carList.add(new Car(3, "car3"));
            }
            public void check(SelectEvent event) {
                System.out.println("in check");
            }
    
    
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to check checkbox like $('#riderCheck').attr('checked','true') on some condition. but the problem is
I have a checkbox with an id of activelist I tried the following but
Recently I switched to mojarra from myfaces and noticed that primefaces datatable checkbox multiple
I have a WPF User control that binds to a DataTable and generates CheckBox
My checkbox column doesn't respond when ticked, apparently it was set to read only,
I have painted a datatable with checkbox's against each row. Now when i select
I have painted a checkbox against each row in my datatable using the following
i am using an checkboslist binding to a datatable. but here i need to
i have a winform datagridview: DataTable table = new DataTable(); table.Columns.Add(Check, typeof(bool)); table.Columns.Add(User, typeof(string));
I want to use checkbox on datatable like that : <h:selectBooleanCheckbox styleClass=selectBooleanCheckbox valueChangeListener=#{CompletedInventoriesBean.changeUID} value=#{CompletedInventoriesBean.isChecked(userinventorieswithuser.id)}

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.