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 se开发者_运维百科e 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>
<h:panelGrid>
is not a grid in the traditional UI sense (i.e. a table with editable fields) - it renders as an HTML<table>
(as written in the docs)- since you don't have a
<h:dataTable>
.. you can't have a dataTable - in order to achieve a grid in the traditional sense, take a look at this, but have in mind it won't be easy for a beginner.
- if you want just dynamically rendered table, check this example (or google more)
From the comments:
Well, that's just a button that add a line to the table.
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 a List<RowObject>
. On the add button you basically just need to add a new RowObject
to the List
(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".
精彩评论