I have this datatable with dynamic columns in my application.
I’m trying to figure out why it shows up with no grid. (And how to enable grid for the datatable).
The JSP: (You can see a few attempts I made, which failed)
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Celsius to Fahrenheit Convertor</title>
</head>
<body>
<f:view>
<h:form styleClass="list-background">
<h:panelGrid footerClass="subtitle" styleClass="list-background"
headerClass="subtitlebig" styleClass="medium"
columnClasses="subtitle,medium">
<h:panelGroup binding="#{myBean.dynamicDataTableGroup}" />
</h:panelGrid>
<h:commandButton value="Add" action="#{myBean.add}" />
</h:form>
</f:view>
</body>
</html>
From the comments:
Then you don’t necessarily need a “dynamic datatable” (this is only useful if the columns are unknown beforehand –which is also explained in the article’s text). Just the
<h:dataTable>is enough. It is backed by aList<RowObject>. On the add button you basically just need to add a newRowObjectto theList(and keep a counter in the request scope so that JSF knows with how many items it should prepare the list). That’s basically all. It’s described with an example in the same “Using datatables” article under the chapter “Add new rows to datatable”.