开发者

generate a jsf dataTable dynamically

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜