JSF provides the ability to include a "selection column" of check boxes in a data table. With this column of check boxes, you can select one or more rows in the table to perform a particular action on. For example, you might select several rows for deletion.
You can set a specific arrangement of properties on an array of records to indicate that the array should be displayed on a web page with a selection column. Then the user can select one or more of the check boxes. EGL indicates which rows were selected by returning an array of integers that represent the indexes of the selected rows. For example, if the check boxes for the first, third, and fourth rows in the data table are selected, EGL sets the array of integers to [1,3,4]. EGL automatically converts 0-based JSF arrays to 1-based EGL arrays.
purchaseList customerPurchase[3];
This
example uses the following sample Record part:record customerPurchase type BasicRecord
custName string;
totalPurchases decimal(10,2);
end
allSelectedRows int[0];
purchaseList customerPurchase[3]
{selectedRowItem = allSelectedRows};
This table includes a small, unlabeled column that contains check box elements. If you click the check box control to select it and go to the Properties view, you can see that this check box is bound not to any fields in the record variable but to the integer array that you defined to hold the indexes of the selected rows.
For example, this JSF Handler uses a selection column in this way:
handler multiSelectPage type JSFHandler
{onPreRenderFunction = onPreRender,
view = "multiSelectPage.jsp"}
//Array of customer records and their purchase amount
purchaseList customerPurchase[3]
{selectedRowItem = allSelectedRows};
//indexes of the selected rows
allSelectedRows int[0];
//Sum of selected purchases
purchaseSum decimal(10,2);
function onPreRender()
//initialize the array of customers
purchaseList[1].custName = "Company A";
purchaseList[1].totalPurchases = "500.23";
purchaseList[2].custName = "Company B";
purchaseList[2].totalPurchases = "232.55";
purchaseList[3].custName = "Company C";
purchaseList[3].totalPurchases = "499.12";
end
function sumRows()
purchaseSum = 0;
counter int = 0;
customerIndexToAdd int;
for (counter from 1 to allSelectedRows.getSize() by 1)
customerIndexToAdd = allSelectedRows[counter];
purchaseSum += purchaseList[customerIndexToAdd].totalPurchases;
end
end
end
record customerPurchase type BasicRecord
custName string;
totalPurchases decimal(10,2);
end
This example assumes that you have dragged the purchaseList array
onto the page to make a JSF data table and that you have bound the sumRows function
and purchaseSum variable to a command button and
output control on the web page, respectively.