English 中文(简体)
如何在 JSF 表格中选择并删除所有行?
原标题:How to select all rows in JSF table and delete them?

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?

问题回答

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.

确实如此,因为数据表(甚至整页)被重新提交,将失去检查状态。

“他们”如何解决这些问题?“他们”

聚焦于您想要实现的目标。 事实上您不想在您的可归并数据表格中选择所有100万个条目, 而是要删除支持您的数据表格的全部列表或收藏 。

为什么不添加一个简单的删除列表的按钮“ 全部删除 ”? 那么您就根本不需要关心选中的框 。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签