Basic Customization > User Interface Customization > Constructing Wizards > Wizard Processing > Solution > Wizards with Multiple Target Objects > Multiple related target objects
  
Multiple related target objects
Other wizards may have multiple related target objects. For example, you might have a wizard that creates a change notice and the change tasks related to that change notice. To create the associations between the change notice and the change tasks, the processor for the change notice will need to know how the objects relate to each other.
The change notice ObjectBean has three child ObjectBeans. The change task ObjectBeans have a parent ObjectBean and no children.
In this case, you would need to write your own FormProcessorController to create the structure of ObjectBeans. This can be a subclass of the DefaultFormProcessorController.
The default controller will create the ObjectBeans for you. You would override its createObjectBeanStructure() method, which is given a flat list of all the ObjectBeans. In that method you would set the parents and children of the ObjectBeans. You pass back a list of all the root ObjectBeans. After you have created the ObjectBean structure, the DefaultFormProcessorController will call the ProcessorBean.newCollection() method which will group the ObjectBeans into ProcessorBeans as follows:
In the diagram above the circles represent the ObjectBeans and the solid lines the relationships between them. The rectangles represent the two ProcessorBeans and the dotted line the relationship between them.
Each ProcessorBean will have its own instances of the ObjectFormProcessor and the ObjectFormProcessorDelegates needed for the objects in it. If the processor for the root ProcessorBean is called "ProcessorInstance1" and the processor for the child ProcessorBean is called "ProcessorInstance2", the processor methods would be called as follows:
Method
Task Performed
1
ProcessorInstance1.preProcess(ObjectBean in Processor Bean 1)
create an instance of a WTChangeOrder2 and store it in the "object" attribute of the bean
2
ProcessorInstance2.preProcess(ObjectBeans in Processor Bean 2)
create three instances of WTChangeActivity2 and store them in the "object" attributes of the beans
3
ProcessorInstance1.doOperation(ObjectBean in Processor Bean 1)
persist the WTChangeOrder2
4
ProcessorInstance2.doOperation(ObjectBeans in Processor Bean 2)
persist the WTChangeActivity2 instances
5
ProcessorInstance1.postProcess(ObjectBean in Processor Bean 1)
create the associations between the change notice and the change tasks
6
ProcessorInstance2.postProcess(ObjectBeans in Processor Bean 2)
none
7
ProcessorInstance1.postTransactionProcess(ObjectBean in Processor Bean 1)
none
8
ProcessorInstance2.postTransactionProcess(ObjectBeans in Processor Bean 2)
none
The tasks could be arranged differently. For example, you could create the associations in method 6 instead of method 5 with the same effect. Or, you could create an ObjectFormProcessorDelegate to create the associations in its postProcess() method. The framework offers the flexibility to modularize your code as best fits your wizard. Just be sure to arrange your tasks correctly relative to the start and end of the main transaction.
Your structure of ObjectBeans could be more complex. For example:
As you can see from the diagram above, ObjectBeans will be placed in different ProcessorBeans if any of the following is true:
the object in the ObjectBeans are different types
the ObjectBeans have a different ObjectFormProcessor
(Note: at this time all the ObjectBeans in the wizard must have the same ObjectFormProcessor.)
the ObjectBeans have a different list of ObjectFormProcessorDelegates
the ObjectBeans have a different parent ObjectBean
The DefaultFormProcessorController will call the processors associated with each ProcessorBean starting at the root ProcessorBean and proceeding down the tree to the leaf ProcessorBeans.