cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamic Child Components

Former Member
0 Kudos

I'm trying to write a parent component that manages a number of child components dynamically at runtime, which all implement a component interface.

I can't find any decent examples on this subject as most seem to skim over the details or assume a concrete dependendancy on a named child component.

The code I am using is as follows but I dont think it is correct:

componentUsage1 = wdThis.wdGetMaxTestPluginComponentUsage();

componentUsage2 = wdThis.wdGetMaxTestPluginComponentUsage();

if(componentUsage1.hasActiveComponent()) {

componentUsage1.deleteComponent();

}

componentUsage1.createComponent("com.x.MaxTestExpensesComp",".com/tmsmaxtestexpenses");

if(componentUsage2.hasActiveComponent()) {

componentUsage2.deleteComponent();

}

componentUsage2.createComponent("com.x.MaxTestProcurementComp","x.com/tmsmaxtestprocure");

wdThis.wdGetMaxTestPluginInterface().initialiseComponent();

I have 2 child components that implement the same component interface. In this example I could just implement a direct relationship from the parent to the 2 child components but I want to pass the component names and dc names at runtime and dynamically load n components.

The parent component has a usage relationship defined to the MaxTestPlugin component interface.

1 - In the example above I am creating 2 component usages. Is this the correct way of creating the components? Can I create two component usages from the relationship wdThis.wdGetMaxTestPluginComponentUsage() at the same time or does the second overwrite the first?

2 - Assuming I can have 2 component usages at the same time, how do I then invoke a method on one of the child components specifically?

I would expect to be able to do something like this: componentUsage1.executePlugin(employeeElement.getEmployeeNumber(),GlobalConstants.INIT_TRIPNO);

I tried to do this by the following code:

IExternalIMaxTestPlugin interfaceController1 = (IExternalIMaxTestPlugin) componentUsage1.getInterfaceController();

interfaceController1.executePlugin(employeeElement.getEmployeeNumber(),GlobalConstants.INIT_TRIPNO);

but this doesn't invoke the method on the child component or do anything at all apart from return without erroring.

The only way I have seen in the examples is to use the usage relationship name:

wdThis.wdGetMaxTestPluginInterface().executePlugin(employeeElement.getEmployeeNumber(),GlobalConstants.INIT_TRIPNO);

But which of the two child components is this calling the method on? To me it doesnt make sense, but it seems to call the method on both.

3 - So does this mean that I can only use one of the child components if they both implement the same component interface and the parent has a usage relationship to the interface rather than to both the child components directly?

Surely I must be missing something? Hopefully someone can help me out? Otherwise the whole concept of loosely coupled components in WebDynpro seems rather inadequate.

Cheers,

Steve

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Incase anyone else has encountered this problem, the following lines do actually work correctly. I'm not sure why they didnt initially:

IExternalIMaxTestPlugin interfaceController1 = (IExternalIMaxTestPlugin) componentUsage1.getInterfaceController();

interfaceController1.executePlugin(employeeElement.getEmployeeNumber(),GlobalConstants.INIT_TRIPNO);