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 6383241
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:37:30+00:00 2026-05-25T02:37:30+00:00

I use <h:dataTable> to list data from database. We have many records in page,

  • 0

I use <h:dataTable> to list data from database. We have many records in page, now I would like to select multiple records with a checkbox in each row. How can I achieve this?

  • 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-05-25T02:37:30+00:00Added an answer on May 25, 2026 at 2:37 am

    I assume that your entity is that well-designed that it has an unique technical identifier, for example the auto increment sequence from the DB.

    public class Entity {
    
        private Long id;
        // ...
    }
    

    If not, you’ll need to add it.

    Then, add a Map<Long, Boolean> property to the bean which is tied to the table.

    private Map<Long, Boolean> checked = new HashMap<Long, Boolean>();
    

    (preinitialization can also happen in (post)constructor, take your pick, at least JSF won’t do it for you; oh, give it a getter as well, a setter is not necessary)

    Then, add a column with a checkbox which maps to the boolean value by entity ID as key.

    <h:dataTable value="#{bean.entities}" var="entity">
        <h:column>
            <h:selectBooleanCheckbox value="#{bean.checked[entity.id]}" />
        </h:column>
        ...
    </h:dataTable>
    <h:commandButton value="Delete" action="#{bean.delete}" />
    

    Now, in the action method associated with the delete button, you can collect and delete the checked items as follows:

    public void delete() {
        List<Entity> entitiesToDelete = new ArrayList<Entity>();
    
        for (Entity entity : entities) {
            if (checked.get(entity.getId())) {
                entitiesToDelete.add(entity);
            }
        }
    
        entityService.delete(entitiesToDelete);
        checked.clear();
        loadEntities();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In past I use dynamic sql and datatable to get data from database. Such
i have problem with load data from Database i use Primefaces (or other use
I have a page with a datatable that reads data from a service class.
I've the data(retrieved from database) in a list but when I use `f:view><html> <body>
I currently use a DataTable to get results from a database which I can
In C#/ASP.NET 3.5, I have a DataTable which pulls rows from the database. I
This is the data I read from database into a datatable. the datatable called
I have two dataTables as follows 1) dtExistingZipCodeInDB (data from database) 2) dtCSVExcelSource (data
Often I use data stemming from a SQL database in R. Typically I do
I have 3 different page where I use list of Users. First page contains

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.