cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamic Component usage

Former Member
0 Kudos

Hi,

I wonder if it's possible to have more compont usages for a component. For example Component A uses component B.

Is it possible, that Component A uses more instances of Component B, where every instance of B has it's own context?

Is this somehow possible?

Best regards,

Peter

Accepted Solutions (1)

Accepted Solutions (1)

siarhei_pisarenka3
Active Contributor
0 Kudos

Hi Peter

Yes, this is possible. Just create another usage of component B. Give the new usage the name different from the first usage. The second component usage will be completely independent from the first one. In general you can have N usages of the same component B in component A.

BR, Siarhei

Former Member
0 Kudos

Hi,

Thanks for your answer.

Is this even possible dynimacly at runtime?

I don't know how many Components of B I need in advance, so I have to do this at runtime.

Which code is necessary for creating a Component Usage at runtime?

Best rergards,

Peter

siarhei_pisarenka3
Active Contributor
0 Kudos

>Is this even possible dynimacly at runtime? Which code is necessary for creating a Component Usage at runtime?

Yes. It's possible, but I would not recommend to do this. The reasons are

- The code for creating a Component Usage at runtime is complicated.

- You have to use internal WebDynpro API, not the public one.

- There are several side effects with the code - restricted place within a component life-cycle, for example.

Instead I'd recommend you to do the following:

- Create the maximum number of component usages at design time (nMax, let say 10 usages).

- Introduce variable-usage counter (0..nMax). The variable will keep the number of design-time usages really used at runtime.

BR, Siarhei

Former Member
0 Kudos

HI,

I can't create the maximum number of component usages (this may be hundred or more).

Can you provide me the code to create component usage at runtime? I will take the risks...

Best regards,

Peter

siarhei_pisarenka3
Active Contributor
0 Kudos

Hi Peter

Main function:

public static String createEmbeddedComponent(
		IWDComponentUsage mainUsage,
		String compName,
		String devCompName,
		String embeddedInterfaceViewName,
		String id,
		IWDController controller,
		String windowName,
		String viewName,
		String rootViewUsageName) 
{
	//create new usage based on default one that was specified in constructor
	IWDComponentUsage currentUsage = mainUsage.createComponentUsageOfSameType(id);
	//get infos for parent component 
	IWDComponentInfo componentInfo = controller.getComponent().getComponentInfo();
	IWDViewInfo viewInfo = componentInfo.findInViews(viewName);
	IWDWindowInfo windowInfo = componentInfo.findInWindows(windowName);
	if (windowInfo == null) {
		throw new IllegalArgumentException(windowName);
	}
	IWDViewUsageInfo rootViewUsageInfo = (rootViewUsageName == null) ?
			windowInfo.getDefaultRootViewUsage() : 
			windowInfo.findInRootViewUsages(rootViewUsageName);
				
	IWDViewUsageInfo usageInfo = rootViewUsageInfo;
	//get infos for embedded component
	IWDAbstractViewInfo embeddedViewInfo = currentUsage.getComponentUsageInfo().getUsedComponent().findInInterfaceViews(embeddedInterfaceViewName);
	if (embeddedViewInfo == null) {
		throw new IllegalArgumentException(embeddedInterfaceViewName);
	}
	//perform embedding
	IWDViewContainerAssignmentInfo containerAssignment = usageInfo.createViewContainerAssignment();
	IWDViewContainerInfo viewContainerInfo = viewInfo.createViewContainer();
	containerAssignment.setViewContainer(viewContainerInfo);
	IWDViewUsageInfo embeddedViewUsage = containerAssignment.createEmbeddedViewUsage();
	embeddedViewUsage.setComponentUsage(currentUsage.getComponentUsageInfo());
	embeddedViewUsage.setView(embeddedViewInfo);
	containerAssignment.setDefaultViewUsage(embeddedViewUsage);
	//create active component for the cloned usage
	currentUsage.createComponent(compName, devCompName);
	//return name of viewContainerInfo as the result
	//it should be used to create corresponding UI control
	return viewContainerInfo.getName();
}

siarhei_pisarenka3
Active Contributor
0 Kudos

...continuation...

Usage:

wdDoInit():

xcompUsageContainerName = createEmbeddedComponent(
	wdThis.wdGetXComponentUsage(), 
	"com.xcom.XExtComp",
	"xcom.com/xextcomp",
	"XExtWindowInterfaceView", 
	"123", 
	wdControllerAPI, 
	"XWindowName", 
	"XViewName", 
	null);

wdDoModifyView():

IWDViewContainerUIElement viewContainer =
    (IWDViewContainerUIElement) view.createElement(
        IWDViewContainerUIElement.class,
        null);
viewContainer.setViewContainer(xcompUsageContainerName);

BR, Siarhei

Former Member
0 Kudos

Hi Siarhei,

thanks for this code, this works fine.

I have to additional questions.

1) How can I access a specific Usage? For example I want to perform a Method on Component Usage with ID 123, how can I do this?

2) Is it possible to map some data from the Context to a specific Usage?

I'm very thankfull for your help.

Best regards,

Peter

siarhei_pisarenka3
Active Contributor
0 Kudos

Hi Peter

1) You have to get the component usage that has been created: currentUsage in the code above. Then you have to cast abstract external component interface to your custom component interface:

IExternalXCompName extCompInterface = (IExternalXCompName) currentUsage.getInterfaceController();
extCompInterface.customMethodInvocation(...);

2) You can access the context of the external component's interface. To establish a mapping is a little bit more complicated:

IWDContext extCompCtx = extCompInterface.wdGetAPI().getContext();

BR, Siarhei

Former Member
0 Kudos

HI,

thanks, this works.

Thanks for your help.

Best regards,

Peter

Former Member
0 Kudos

Hello,

Did your approach work only when executed in wdDoInit() too? Meaning that u know the number of dynamic usages is known on loading of the component.

I want create dynamic usages on clicking a button. The behavior i want to make is that when clicking a a node in a tree, tabs are created with in every tab a "details" view, depending on the node clicked in the tree.

Kind regards.

Former Member
0 Kudos

Hi,

this approach worked not only in the wdDoInit(). I was able to create component usage at dynamic at runtime.

So I think for you it's possible to create the dynamic usages by clicking a button.

Best regards,

Peter

Former Member
0 Kudos

Hi,

is it possible to embed components from other DC's too? In design-time i would add a dependency for that, is this possible in runtime too?

best regards, thomas

Answers (0)