This is the constructor code:
public TreeExample() throws SQLException {
TreeItem node1 = null;
String url = "jdbc:oracle:thin:@xyz";
String user = "dummy";
String password = "dummy";
root = new ArrayList<TreeItem>();
Connection connection = DriverManager.getConnection(url, user, password);
Statement statement = connection.createStatement();
String sql = "SELECT * FROM HEALTH_CHECK_QUERIES ORDER BY HEADER_TYPE ASC";
ResultSet result = statement.executeQuery(sql);
String previousheadernode = "First";
while (result.next()) {
String headernode = result.getString("Header_Type");
String childnode = result.getString("Detail_Type");
if (!headernode.equals(previousheadernode))
{
node1 = new TreeItem(headernode, headernode);
root.add(node1);
previousheadernode = headernode;
}
ArrayList<TreeItem> node1Children = new ArrayList<TreeItem>();
TreeItem node1Child1 = new TreeItem(childnode, childnode);
node1Children.add(node1Child1);
node1.setChildren(node1Children);
}
setListInstance(root);
}
这就是我创建树的方法。但子节点没有根据需要添加到父节点(必须将D1和D2添加到父节点H1)。
请建议我改变。有没有其他简单的方法来实现相同的目标?
我的表格如下:
header_details detail_type query
--------------------------------------------------
H1 D1 SELECT * FROM xyz;
H1 D2 SELECT * FROM xyz;
H2 D21 SELECT * FROM xyz;
H2 D22 SELECT * FROM xyz;
H3 D3 SELECT * FROM xyz;
H3 D32 SELECT * FROM xyz;
This is how I am creating tree.But the child nodes are not getting added to the parent as required(D1 and D2 must be added to parent node H1).
请建议我改变。有没有其他简单的方法来实现相同的目标?
先谢谢。
答案 0 :(得分:0)
你在这里做错了,因为它不是ADF的做事方式 了解如何使用模型和应用程序模块。
在adf中有很多样本如何使用树模型: