You need to sign in to do that
Don't have an account?
Update index values in List upon removal (List out of bounds error)
I am currently having an issue with a dynamic list that has the ability to add rows as needed. This functionality is working fine but I am running into an issue with the deletion of rows.
The user has the ability to add 1 row or 25 rows. Each row has the ability to be removed from the entry page. Issue is when they add 25 rows (or even a few) and delete a row in the middle of the list then go to delete a higher value row it will produce the list out of bounds error.
Example: User adds 25 rows. They need to delete row 15 and 20. User removed 15 first and when they go to delete 20 it crashes with a list out of bounds exception.
I understand why it does this but am trying to figure out how to re-assign index values once the list is modified.
Here is the delete method as it stands right now:
public void DelPersonnel() { system.debug('selected row index---->'+selectedRowIndex); if(count != 1) //Prevent crash on remove 1 { lstInner.remove(Integer.valueOf(selectedRowIndex)-1); //something needs to go here to change the row values! count = count - 1; numpersonnel = numpersonnel - 1; } }
I am assuming I need to add a for loop to reassign row index values over the deleted - can anyone assist? I am unsure on how to change the index value.
Thanks in advance
Provide the code of your list lstInner, how do you implement it.
Apex:
VF:
I don't have time to write out an entire sample, but here's how I generally approach this issue:
In other words, the size is determined by the collection, which already knows how large it is. Try not to duplicate logic that's already available. Note that I don't have to store the index of the inner class in each row, as the parent object knows how to handle which row is being removed. The row item requests for its own removal, and the main controller satisfies this request.