Skip to Main Content

Java Development Tools

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Deleting Rows from the table

727467Oct 4 2011 — edited Oct 4 2011
Hi,

I have a requirement to delete selected rows of a table. The table is bound to ArrayList of Employee objects. No bindings or no adf model related code.

I have implemented the logic by putting " boolean selected" attribute in the Employee class to track the selection of the rows. In the delete button action I am traversing through the array list and deleting the objects from the array list if "isSelected()" true on the employee object. The logic is working fine.

But this requires introducing a new variable in the Employee class. Is there any possibility I can get selected rows and delete them from the table with out introducing the new variable in Employee class. I tried getSelectedRowKeys(), getSelectedRowData() methods on the table component, But they did not yield the expected behavior.


The following is the implementation details:

public String deleteEmployees_action() {
// Add event code here...
System.out.println("Delete method invoked...");
List selectedEmployees = new ArrayList<EmployeeDTO>();

for(int i = 0; i < employees.size(); i++) {
EmployeeDTO employee = employees.get(i);
if(employee.isSelected() == true)
selectedEmployees.add(employee);
}

for(int i = 0; i < selectedEmployees.size(); i++) {
getEmployees().remove(selectedEmployees.get(i));
}
return null;
}

Thansks,

S R Prasad
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 1 2011
Added on Oct 4 2011
12 comments
498 views