动态绑定到动态表组件

时间:2013-06-21 03:12:26

标签: jsp jsf woodstock

根据这个site,必须将数据源放到设计器上才能创建数据提供者。然后动态创建表并绑定到数据提供者。

但是,如果我的Web应用程序充当用户的GUI,用户可以从另一个页面创建表并在另一个页面上查看表。如何显示/绑定新创建的表,因为不存在数据提供者?

我已经设法稍微努力了。但是,我不明白为什么我的rowGroup中没有值/数据?

ModificationPage.java

public class ModificationPage extends AbstractPageBean {
    @Override
    public void prerender() {
        try {
            tempRowSet.setDataSourceName("java:comp/env/jdbc/testDB_MySQL");
            tempRowSet.setCommand("SELECT * FROM " + this.tempTable.toString());
            tempRowSet.setTableName(this.tempTable.toString());

            tempDataProvider.setCachedRowSet(tempRowSet);
        } catch (SQLException ex) {
            Logger.getLogger(ModificationPage.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void tableID_processValueChange(ValueChangeEvent vce) {
        // Reset the gridpanel so that only the selected table is displayed
        if (gridPanel2.getChildCount() > 1) {
            gridPanel2.getChildren().clear();
        }

        this.tempTable.append(vce.getNewValue());

        Table dynamicTable = new Table();
        dynamicTable.setId(tempTable.toString());
        dynamicTable.setTitle(tempTable.toString());
        dynamicTable.setPaginateButton(true);
        dynamicTable.setPaginationControls(true);

        // Create the Table Row group dynamically
        TableRowGroup rowGroup = new TableRowGroup();
        rowGroup.setId("rowGroup1");
        rowGroup.setSourceVar("currentRow");
        rowGroup.setValueBinding("sourceData", getApplication().
                createValueBinding("#{ModificationPage.tempDataProvider}"));
        rowGroup.setRows(5);

        // Add the table row group to the table as a child
        dynamicTable.getChildren().add(rowGroup);

        int test1 = rowGroup.getChildCount(); // returns 0, why?
        int test2 = rowGroup.getRowCount(); // returns 0, why?
        int test3 = rowGroup.getColumnCount(); // returns 0, why?

        for (int i = 0; i < rowGroup.getRowCount(); i++) {
            // Create the table column
            TableColumn tableColumn = new TableColumn();
            tableColumn.setId(tempRowSet.getColumnNames()[i]);
            tableColumn.setHeaderText(tempRowSet.getColumnNames()[i]);

            // Add the table Column to the table row group
            rowGroup.getChildren().add(tableColumn);

            // Create the Static text and set its value
            StaticText staticText = new StaticText();
            staticText.setValueBinding("text", getApplication().
                    createValueBinding("#{currentRow.value['borrowerID']}"));

            // Add the static text to the table column1
            tableColumn.getChildren().add(staticText);
        }

        gridPanel2.getChildren().add(0, dynamicTable);

    }

}

谢谢。

0 个答案:

没有答案