0
votes

I have a JSF table with check boxes and pagination. I have the following question: I want to select all rows into all table pages and delete them. The simple way is to create a Java hashmap and store the keys. Then Java method will delete them using the keys into the hashmap, but what will happen if the hashmap is more than 1 million? Maybe memory leak? Maybe the solution is to use this simple JavaScript to select all checkboxes:

//Select all checkbox
function selectall(){     
    $('button').click(function() {
        $("[type=checkbox]").prop("checked", true);
    })​     
}

//Unselect all checkbox
function selectall(){     
    $('button').click(function() {
        $("[type=checkbox]").prop("checked", false);
    })​     
}

There are two problems that I face: 1. If I use the JavaScript to select all checkboxes maybe only the checkboxes on the first page will be selected, if I switch on the second page there will not be selected checkboxes. The JavaScript only works for one page. 2. If I select all checkboxes with the JavaScript when I click on the delete button how the Java method would know that every checkbox is selected into the table and delete the rows? How I can solve these problems?

1

1 Answers

2
votes

If I use the JavaScript to select all checkboxes maybe only the checkboxes on the first page will be selected, if I switch on the second page there will not be selected checkboxes.

That is true, because the datatable (or even the whole page) are re-rendered and will loose their checked status.

How I can solve these problems?

Focus on what you try to achieve. In fact you don't want to select all one million entries in your paginated datatable but want to delete the whole list or collection that is backing your datatable.

Why not adding a button "Delete all" that simply empties out the list? Then you don't need to care about select boxes at all.