1

我实际上按照下面的链接将列和行数据添加为动态的,对如何在 xhtml 上显示有点困惑。任何帮助

http://balusc.blogspot.com/2006/06/using-datatables.html#PopulateDynamicDatatable

List<String> strlist = new ArrayList<String>();
        List<List<String>> dynamicListynamicList = new ArrayList<List<String>>();
        strlist.add("Name");
        strlist.add("SSN");
         for(String columnName : columnNamesList){
             strlist.add(columnName);
    }

         List<String> rowData = new ArrayList<String>();
         for(String otherList : listData){
             try {
                 rowData.add(otherList.getName());
                 rowData.add(otherList.getId());
                    if(otherList.getAmount() != null){
                         for(BigDecimal amount : otherList.getAmount()){
                             if(amount != null){
                                 rowData.add(amount.toString());
                             }else{
                                 rowData.add("");
                             }
                         }
                    }else{
                        for(String s : strlist){
                             rowData.add("");
                        }
                    }

                 } catch (Exception e) {
                    // TODO: handle exception
                     e.printStackTrace();
                }
                 dynamicListynamicList.add(Arrays.asList(rowData.toArray(new String[rowData.size()] )));
            }

        String[] strarray = new String[strlist.size()];
        dynamicHeaders =   strlist.toArray(strarray );
        populateDynamicDataTable(dynamicListynamicList);

        private void populateDynamicDataTable(List<List<String>> dynamicList2){
             HtmlDataTable dynamicDataTable = new HtmlDataTable();
             for (int i = 0; i < dynamicList2.get(0).size(); i++) {
                 HtmlColumn column = new HtmlColumn();
                 dynamicDataTable.getChildren().add(column);
                 HtmlOutputText header = new HtmlOutputText();
                    header.setValue(createValueExpression("#{dynamicItemColumn[" + dynamicHeaders[i] + "]}", String.class));
                    column.setHeader(header);
                    HtmlOutputText output = new HtmlOutputText();
                    output.setValueExpression("value",
                        createValueExpression("#{dynamicItem[" + i + "]}", String.class));
                    column.getChildren().add(output);
             }

             dynamicDataTableGroup = new HtmlPanelGroup();
             dynamicDataTableGroup.getChildren().add(dynamicDataTable);
             setDynamicList(dynamicList2);

随着数据的添加,每件事都正常工作,现在我不确定,我很抱歉,如何在 jsf 页面(xhtml)中迭代,以显示相关的列和行数据..

4

0 回答 0