Java Reference
In-Depth Information
This will result in the appropriate instance variable and corresponding getter
and setter methods being generated in our managed bean, as well as the binding
attribute being added to the <webuijsf:tableRowGroup> tag. We can now use
the generated TableRowGroup instance to obtain the row that was clicked on.
Invoking the getRowKey() method on TableRowGroup returns an instance of com.
sun.data.provider.RowKey . The returned RowKey instance corresponds to the
row that was clicked on. By invoking its getRowId() method we can obtain a
String representation of the index for the row that was clicked, which happens to
correspond to the index of the corresponding Customer object in the customerArray
property in the SessionBean1 managed bean. Therefore by converting the returned
value to an int we can obtain the appropriate Customer object.
Once we have obtained the appropriate Customer object from the customer array, we
need to set it as the session scoped customer managed bean. We do this by invoking
setValue() with the appropriate UEL expression as the first parameter and the
Customer instance as the second parameter. The reason we are doing this is so the
Edit page can get a hold of it, display its data, and update the database when its Save
button is pressed.
As can be seen in the code previous, we need to explicitly specify that we
want the Customer object in the session scope. If no scope is specified,
setValue() by default will attach it to the request.
Now that we have implemented the logic to add and update customer data, we need
to implement the logic to delete customers from the database. Double-clicking on the
Delete Selected button generates its corresponding action listener method.
public String deleteButton_action() {
if (tableRowGroup1.getSelectedRowsCount() > 0) {
RowKey[] selectedRowKeys =
tableRowGroup1.getSelectedRowKeys();
Customer[] customerArray =
getSessionBean1().getCustomerArray();
for (RowKey rowKey : selectedRowKeys) {
customerDAO.remove(
customerArray[Integer.parseInt(rowKey.getRowId())]);
}
}
return null;
}
 
Search WWH ::




Custom Search