gpt4 book ai didi

java - 如何从 ADF 中的 Java 类创建数据控件和 View 对象

转载 作者:行者123 更新时间:2023-12-01 12:49:10 24 4
gpt4 key购买 nike

我有一个 XML 文件

<employees>
<employee id="111">
<firstName>Rakesh</firstName>
<lastName>Mishra</lastName>
<location>Bangalore</location>
</employee>
<employee id="112">
<firstName>John</firstName>
<lastName>Davis</lastName>
<location>Chennai</location>
</employee>
<employee id="113">
<firstName>Rajesh</firstName>
<lastName>Sharma</lastName>
<location>Pune</location>
</employee>
</employees>

我使用将其解码到 Employee 类中

public class DOMParserDemo {

public static void main(String[] args) throws Exception {
//Get the DOM Builder Factory
DocumentBuilderFactory factory =
DocumentBuilderFactory.newInstance();

//Get the DOM Builder
DocumentBuilder builder = factory.newDocumentBuilder();

//Load and Parse the XML document
//document contains the complete XML as a Tree.
Document document =
builder.parse(
ClassLoader.getSystemResourceAsStream("xml/employee.xml"));

List<Employee> empList = new ArrayList<>();

//Iterating through the nodes and extracting the data.
NodeList nodeList = document.getDocumentElement().getChildNodes();

for (int i = 0; i < nodeList.getLength(); i++) {

//We have encountered an <employee> tag.
Node node = nodeList.item(i);
if (node instanceof Element) {
Employee emp = new Employee();
emp.id = node.getAttributes().
getNamedItem("id").getNodeValue();

NodeList childNodes = node.getChildNodes();
for (int j = 0; j < childNodes.getLength(); j++) {
Node cNode = childNodes.item(j);

//Identifying the child tag of employee encountered.
if (cNode instanceof Element) {
String content = cNode.getLastChild().
getTextContent().trim();
switch (cNode.getNodeName()) {
case "firstName":
emp.firstName = content;
break;
case "lastName":
emp.lastName = content;
break;
case "location":
emp.location = content;
break;
}
}
}
empList.add(emp);
}

}

//Printing the Employee list populated.
for (Employee emp : empList) {
System.out.println(emp);
}

}
}

我想在 ADF 中创建一个 UI,其中的字段将填充输出数据。

有人可以指导我如何实现它吗?

最佳答案

请参阅以下教程,了解如何从 Java 类创建数据控件:Using Bean Data ControlsJava Class Data Controls and ADF Binding

关于java - 如何从 ADF 中的 Java 类创建数据控件和 View 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24380209/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com