2011-01-31 76 views
-2

我需要動態創建一個jsf數據表,這意味着 列中的任何一列都會變化,並且將在運行時決定 任何示例都將被理解。動態生成一個jsf數據表

-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:inputText value="#{section.columnValue}" /> 
           </ice:panelGroup> 
          </ice:columns> 
         </ice:dataTable> 
+5

你的任何努力也將不勝感激。這不是一個代碼生成機器。 – 2011-01-31 21:56:37

回答

3

也許你可以綁定一個數據表:

<h:dataTable id="myTable" bind="#{myBean.table}"... /> 

豆:

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 
} 

有關ValueExpression的更多信息可以發現here

並隨意使用h:dataTable或rich:dataTable。 h:column或rich:列相同,只需檢查組件名稱here

1

嘗試拼圖C:的forEach或UI:重複(如果你使用的是小面)和渲染TR(外環),TD(內環)標記自己