I need to create a jsf dataTable dynamically which means no of columns will vary and will be decided at run time Any example will be appreciated.
-SPD
<ice:dataTable var="item"
value="#{section.rowDataModel}">
<ice:columns value="#{section.columnDataModel}"
var="column">
<f:facet name="header">
<ice:panelGroup>
<ice:outputText value="#{column.columnName}" style="#{column.columnWidth}"/>
</ice:panelGroup>
</f:facet>
<!-- display the table cell values-->
<ice:panelGroup
style="text-align: center; white-space: nowrap;">
<ice:inp开发者_开发知识库utText value="#{section.columnValue}" />
</ice:panelGroup>
</ice:columns>
</ice:dataTable>
Maybe you can bind a datatable:
<h:dataTable id="myTable" bind="#{myBean.table}"... />
Bean:
public class MyBean() {
private HtmlDataTable dt;
public MyBean() {
initTable();
}
private initTable () {
dt = new HtmlDataTable();
//Add here your columns using HtmlColumn
HtmlColumn hc = new HtmlColumn();
//You can set colum values using ValueExpression
//And add column to table using getChildren().add(hc);
(...)
}
//Getters and setters
}
More info about ValueExpression can be found here.
And feel free to use h:dataTable or rich:dataTable. Same for h:column or rich:column, just check the components name here.
Try to nest c:forEach or ui:repeat (if you are using facelets) and render tr (outer loop),td (inner loop) tags yourself
精彩评论