In a blur from Price and Package I would like to have code to calculate in the client side (javaScript) the TotalAmount. For this I have the following code->
var price = CAF.model('#{activePageBean.clientIds['V_CELL_PRICE_ID']}').getValue();
var package = CAF.model('#{activePageBean.clientIds['V_CELL_PACKAGE_ID']}').getValue();
if(preco != "" && uniVen != "")
{
var mulTotal = (preco * uniVen).toFixed(2);
CAF.model('#{activePageBean.clientIds['V_CELL_TOTALAMOUNT_ID']}').setValue(mulTotal);
}
Is this the best way to get the value from control in a cell inside a table? If my table contains 100 rows this getValue gets the correct value? In terms of performance is this ok?
Is there any better way to get (in javascript) the value
A better approach might be to use the client-side table model to list the rows in the table, and then for each row lookup the control and attach a listener. A table model’s list() method will return a list of row models, one for each row in the table’s current page. A row model’s getControl(id) method will lookup the client-side id of a control in the row, given the control’s server-side id.
In this example, the following code should lookup all the dropdowns in a table, given a server-side table id of myTableId and a server-side dropdown id of myDropdownId:
var table = CAF.model("#{activePageBean.clientIds['myTableId']}";
var rows = table.list();
for (var i = 0; i < rows.length; i++) {
var row = rows[i];
var dropdownId = row.getControlId("myDropdownId");
var dropdown = CAF.model(dropdownId);
dropdown.addValueChangeListener(function(id, oldValue, newValue) {
alert(id + " changed from " + oldValue + " to " + newValue);
});
}