Get number of rows in a result table

I have an async table with remove row button in it. User is allowed to remove all the rows from the table. If all the rows are moved, then I want to hide the table (which now consists only of header and footer). Over “Remove Row” button, I used a custom script and used following code to get number of rows in the table and if it’s zero, then hide the table.

       if(CAF.model('#{activePageBean.clientIds['resultTable']}').getRowCount() == 0)
           {
                 CAF.model('#{activePageBean.clientIds['resultHideablePanel']}').setVisible(false);
           }

But something is not right in the code. The hideable panel’s visibility is not being set to false.

I am on version version 9.6. I tried CAF:cid instead of activePageBean.clientIds, but it didn’t help. What am I missing here?

Thanks.

Hi Altaf,

please check if you need to redraw/rerender the hideable panel after changing its visibility status.

Or check if there is a hide() function.

Regards,
Holger

I have used setVisible() function all over the places in the portal and it all works fine. I am doing refresh on the hideable panel in “Remove Row” button’s on-click event.

Looks like something is wrong in the way I am using getRowCount() to retrieve number of rows in the table.

Is your custom script control rendered inside of a table column? In that case your clientId expressions would resolve to the id of the row of the table that is currently being rendered, instead of the clientId of the table control itself.

Perhaps you could just use a table row change listener that is in a script block control that is rendered after the table control whose value is something like this:

CAF.model('#{caf:cid("resultTable")}').addRowChangeListener(
    function(tableid, rowId, type) {
        if (type == 'remove') {
            if (  CAF.model ( tableid ).getRowCount () == 0 )  {
                CAF.model('#{caf:cid("resultHideablePanel")}').setVisible(false);
            }
        }
    }
);

I am using this code in custom script for the control placed inside a table column, it’s still not working.

I have attached the code.

Please let me know what I am missing here.
HideTable.zip (97.3 KB)

Your Custom Script is inside of a table column, so it is resolving the “phoneTable” clientId as the ID of the current table row.

For example:

CAF.model('jsfwmp5370:defaultForm:phoneTable:__row__new2565').addRowChangeListener(..)

If you get rid of that Custom Script control inside the table column and add a new “Script Block” control after the table control with the snippet I specified earlier, it should work for you.

Perfect. Using “Script Block” outside the table worked.

Thank you.