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.
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.
Related
I have a Vaadin 14 Flow application that presents a grid of tasks that can be added to and deleted from as well as editing a selected task. Currently I have it set up so that if the user clicks a row (single select), it opens an editor so they can edit the task.
What I'd like to do is have a checkbox on each row that can be used as a multi-row selector to allow deleting multiple rows.
Would it be easier to just have the table be multiple selection enabled and just delete whatever row(s) are selected? I assume multi-selection allows the usual shift-click to select a contiguous range and control-click to select rows at random.
If I switch to multi-select, how will this affect the ability to simply click a row and have it open an editor for that row? If multiple rows are selected, what is likely to happen?
Update:
I'd never used multi-select until now. I didn't realize it provides checkboxes out of the box (no pun intended).
I had never used multi-select before and didn't realize that using that technique automatically adds a checkbox at the front of the row. Problem solved.
I have a very basic problem with jtable. I have a jtable that has multiple columns with one of column having a button. When i click on that button a panel drops, and asks to select an option from given options. When i select that option, value replaces in one of the column.
Now, i want when i select multiple rows, and do the same thing as above, it should replace that column in all the selected rows.
Problem: Currently, my table is losing selection when i am clicking the button in one of the column in jtable after multiple row selection.
I searched google and stackoverflow a lot, but could not find anything meaningful. Anyhelp or sample code is appreciated.
Thanks
If I understood your problem correctly then the solution is fairly simple.
First of all the issue probably occurs because once you click on the button java sets a new focus on the button and therefore clearing the focus on the other rows. That won´t be a problem in a single selection because you still click into the selected row, however doing that with multiple rows in one go won´t work that way.
To solve this you need to save your previous selections in something like an ArrayList and after the whole option thing you can apply the changes to every element in the ArrayList and reload the table.
A cleaner and more intuitive approach though would be to place the button outside of the JTable.
I want a page in which list is need to be displayed and further I need to refine the result of list based on checked checkbox. i have set of checkboxes like filter by date , filter by status etc. In each set of checkbox, multiple options can be selected.
what i have tried till now is that i m retrieving separate list for each checkbox selected in the controller class. can u tell me how can i merge all the list in single based on selection (I also don't want duplicate entries) and pass it to my view.jsp or any other way to do this.
and one more thing when m using onClick for radio or checkox html input tag, action is triggered but tick is not getting retained in view page. Option is getting unchecked automatically on page refresh
I need to develop an jsp application where I need to bring data from database table and display it in table in frontend dynamically. I need to make this table editable. The user can edit any number of rows which all should be updated in the database table automatically on clicking Save Changes button.
I am able to bring data from database table and display it. I am displaying the values obtained from table in each cell of input type text of form. We am i clicking edit button i am able to update only last edited row in the table.
Please tell how to update all the edited rows at a time.
Provide two links for view and edit
of table values
In view keep the values simply in td element of table.
In edit , use input elements of type text inside td element.
If you want to do everything in same page, Ajax can be used for both view and edit.
How many JSPs to create to maintain one table for data entry. Add.jsp to enter a new record and Update.jsp to update an already entered record. Is this a good idea or create only one jsp and use that for add and update using some parameter as all the fields and functionality remains same. Only difference is at the time of update few fields will be disabled and you need to pre-populate the form. I can use struts or jsf to develop this.
Better use one page, and differentiate between new and existing based on some criteria - for example, if the id of the object is 0.
Even if you make two pages, you can include the common content so that you don't copy-paste.
I like the one page approach too.
You could have a dropdown box containing the ids' or some other value that provides an easy way for the user to find a specific record and whatever other html elements you need on the page for displaying a record.
They make a choice using the drop down box if they wish to edit a record and then that records data is displayed on the page for editing, the user enters the corrections and hits the submit button.
If they want to enter a new record, then they do not make a choice using the dropdown box and instead just fill in the fields on the page and hit submit.
When posting back to the page you can check and see if a selection was made using teh dropdown box and if not enter a new record and if a choice was made then you update the record that corresponds to the selection made from the dropdown box.