The simplest variable-element grid component in the basic JSF armoury is the dataTable. Unlike the panelGrid, which has a static number of elements, the dataTable can have a variable number of rows, based on the number of rows in the DataModel object that backs it.
A variable number of columns is a bit trickier, since the original JSF spec didn't cover this. Back then, you had to resort to brute force, binding the actual container element to a backing bean, then putting login in the backing bean to dynamically construct UICOmponent tree elements and attach them in their proper places. Not something to do just for idle amusement.
In JSF2 (or JSF 1 with Facelets added on), you can use the Facelets ui:repeat tag to do a variable number of elements and avoid the platform-specific
Java code.
Some extension tagsets, such as RichFaces also have elements that can handle multiple sub-components relatively easily as well. I just discovered (and used) the "columns" tag that permits the number of columns in their extended dataTable to be set dynamically, in fact. It made short work of what I'd expected to be a long project.