根据这个站点,必须将 DataSource 放到设计器上才能创建数据提供者。然后动态创建表并绑定到数据提供者。
但是,如果我的 Web 应用程序用作用户的 GUI,用户可以从另一个页面创建表格并在另一个页面上查看它。由于不存在数据提供者,如何显示/绑定新创建的表?
我已经设法稍微解决了这个问题。但是,我不明白为什么我的 rowGroup 中没有值/数据?
修改页面.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);
}
}
谢谢你。