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

  • Home
  • SEARCH
  • 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 9216695
In Process

The Archive Base Latest Questions

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

I am using primefaces datatable for checkbox based selection and try to implement given

  • 0

I am using primefaces datatable for checkbox based selection and try to implement given example. They used Model say, userModel which could implement SelectableDataModel interface. I don’t want to use model so I used rowKey for this purpose.

E.g

datatable.xhtml

<p:dataTable id="table" var="item" value="#{userBean.allItems}"
       paginatorPosition="bottom" paginator="true" rows="3"
       selection="#{userBean.selectedItems}" rowKey="#{item[0]}">

       <p:column selectionMode="multiple"/>

       <p:columns value="#{userBean.itemColHeader}" columnIndexVar="colIndex" var="colName" >
       <f:facet name="header" >
           <h:outputText value="#{colName}"/>
       </f:facet>
           <h:outputText value="#{item[colIndex]}"/>
       </p:columns>
</p:dataTable>

Here,

allItems = ArrayList<ArrayList<String>>

selectedItems = ArrayList<ArrayList<String>>

selectedItems = ArrayList<String>

userBean.java

@ManagedBean(name="userBean")
@ViewScoped
public class userBean implements SelectableDataModel {

    private ArrayList<ArrayList<String>> selectedItems;

    public ArrayList<ArrayList<String>> getSelectedItems() {
        return selectedItems;
    }

    public void setSelectedItems(ArrayList<ArrayList<String>> selectedUsers) {
        this.selectedItems = selectedItems;
    }
}  

My problem:

1) When I select mulitple rows, selectedUsers remains empty.
2) After selecting next page, previous selection get lost. 

I went through @BelusC blog and found that binding is possible solution but unable to solve my problem with his instructions. Is converter needed..? Is there any thing wrong with my approach. Thanks

Update:1

The reason behind using Arraylist of Arraylist(allItems) is only to make datatable generic. I need not to bother about the no of columns while drawing datatables. That is why I want to retrieve the selected items which should not depend on object(like: car[ ] selectedcars)

  • 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-18T02:28:20+00:00Added an answer on June 18, 2026 at 2:28 am

    I had similar issues and I solved it using <p:ajax>.

    First I would do as akoskm says and have a unique row key.

    Then I would use an array (List<String>[]) (List is more generic than ArrayList) for selectedItems

    And finally you can add:

    <p:dataTable ...>
        <p:ajax event="rowSelectCheckbox" process="@this"/>
        <p:ajax event="rowUnselectCheckbox" process="@this"/>
        <p:ajax event="toggleSelect" process="@this"/>
    </p:dataTable>
    

    Just make sure you have an <h:form> around the table

    That will make sure that the component pushes the data to the bean. I’m not sure if it will solve the pagination problem though, let me know.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm following the example given at http://www.primefaces.org/showcase/ui/datatableRowSelectionSingle.jsf I'm using this as a portlet in
I'm trying to filter a dataTable using Primefaces much like this example . (In
Using the PrimeFaces Demo filtering DataTable ( https://www.primefaces.org/showcase/ui/data/datatable/filter.xhtml ) as an example, I would
I have implemented org.primefaces.model.SelectableDataModel . Now when rendering my <p:dataTable> based on the SelectableDataModel
I am using primefaces datatable with clickable rows and I need to find way
I am using PrimeFaces <p:dataTable> with pagination. I use <h:selectBooleancheckbox> with a Map property
I'm using Primefaces 3.3.1 and have question. I have p:commandButton inside p:column of p:dataTable.
I'm having the following issue with a dataTable using PrimeFaces 3.4.1 and JSF 2.1.6.
I'm using PrimeFaces 3.4.2 and I have to use <p:dataTable> . I want fixe
I am using JSF 2.0 and Primefaces 3.4.2, I have a datatable populated using

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.