on 12-21-2009 7:32 AM
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
>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
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();
}
...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
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
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
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.
User | Count |
---|---|
80 | |
9 | |
9 | |
7 | |
7 | |
6 | |
6 | |
6 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.