Number of rows in a table

On page load, I need to show a table only if there is at least one row in the table. I am refreshing the table during page initialization.

I used following script in script block value:


var alertTable = CAF.model('#{activePageBean.clientIds['alertTable']}');
if (alertTable.getRowCount() > 0)
{CAF.model('#{activePageBean.clientIds['alertPanel']}').setVisible(true);}

The script block is outside the table. I am unable to figure out what’s wrong with the code as it doesn’t seem to work.

It looks like you are only handling the case where the alert panel starts out hidden?

Maybe try the following to handle both of the possible initial visibility states:

var alertTable = CAF.model('#{activePageBean.clientIds['alertTable']}');  
var alertPanel = CAF.model('#{activePageBean.clientIds['alertPanel']}');
alertPanel.setVisible(alertTable.getRowCount() > 0);

To add to it, you may also need to place this script at the bottom of the page, just so all the elements are loaded before executing the script.