Single instance of a nested business object
Use the
setWithCreate function to create a single instance of nested
business object.
Before you begin
The following example code shows how you would normally have to create code for an intermediate
(child) object from a higher level (parent) object in order to create a third-level (grandchild)
object. The XSD file would look like
this:
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:complexType name="Parent">
<xsd:sequence>
<xsd:element name="name" type="xsd:string"/>
<xsd:element name="child" type="Child"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="Child">
<xsd:sequence>
<xsd:element name="name" type="xsd:string"/>
<xsd:element name="grandChild" type="GrandChild"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="GrandChild">
<xsd:sequence>
<xsd:element name="name" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>About this task
If you used the traditional "top-down" method to set the business object data, you would have to
process the following code specifying the child and grandchild objects before setting the data in
the grandchild
object:
DataObject parent = ...
DataObject child = parent.createDataObject("child");
DataObject grandchild = child.createDataObject("grandChild");
grandchild.setString("name", "Bob");You can use a more efficient method by using the
setWithCreate function to
simultaneously define the grandchild object and set its data, without having to specify the
intermediate child object. The following example code shows how you would accomplish this
task:DataObject parent = ...
parent.setString("child/grandchild/name", "Bob");Results
The lower-level business object data is set without having to reference the intermediate-level business object. An exception occurs if the path is not valid.
This topic only applies to BAW, and is located in the BAW repository. Last updated on 2025-03-13 12:15