cancel
Showing results for 
Search instead for 
Did you mean: 

ComponentUsages

Former Member
0 Kudos

Hi all,

my application has 2 component usage and for certain reasons I need to iterate over them. I'm using the following code:

<i>Collection ComponentUsages = wdComponentAPI.getComponentInfo().getComponentUsages();

for (Iterator iter = ComponentUsages.iterator(); iter.hasNext();) {

IWDComponentUsageInfo ComponentUsageInfo = (IWDComponentUsageInfo) iter.next();

String CompUsageName = ComponentUsageInfo.getName();

}</i>

but it iterate only over the second item in the collection. What's wrong?

Thanks,

Stefano

Accepted Solutions (1)

Accepted Solutions (1)

padmashree_b
Explorer
0 Kudos

Hello Stefano,

From where do you want to destroy these component instances?

Component WDa must already have the component usages. So you can create a method in the component controller and use typed APIs to destroy the component instance that is created for WDb and WDc.

The below snippet could be used:

if(wdThis.wdGetWdbComponentUsage().hasActiveComponent()) {

wdThis.wdGetWdbComponentUsage().deleteComponent();

}

This method in the controller can then be even called from a View.

Hope this helps.

Thanks and Best Regards,

Padma

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi all,

I've solved the previous question with the following code:

<i>Object[] CompUsageInfoArray = CompUsages.toArray();

for (int i = 0; i < CompUsageInfoArray.length; i++) {

IWDComponentUsageInfo CompUsageInfo = (IWDComponentUsageInfo) CompUsageInfoArray<i>;

String CompUsageName = CompUsageInfo.getName();

}</i>

Now the question is how can I get the ComponentUsage from the ComponentUsageInfo?

Stefano

Sunitkroy
Participant
0 Kudos

Hi

Just go to the context menu of ComponentUsage and you will find 'add to public part' option.Give a proper name there. Now come back to the ComponentUsageInfo component where you can find 'used webdynpro component' where you have to give the name that you gave as the public part of the ComponentUsage component. Now all the functionality of ComponentUsage is available in the ComponentUsageInfo component.

Former Member
0 Kudos

Hi Sunit,

I try to explain better my requirements.

I have 3 WD components: WDa, WDb and WDc.

Component WDb and WDc expose public part and WDa uses these component via their public part.

In Wda I want to know which are the used component and if they are istantiated destroy them.

I obtain the list of used WD component using <i>Collection ComponentUsages = wdComponentAPI.getComponentInfo().getComponentUsages();</i>. Now I need to check for each used component if it is istantiated (hasActiveComponent) and if so destroy them. What I need to do this is a reference to the IWDComponentUsage, so how can I get this?

BeGanz
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hallo Stefano,

there is one major drawback with our current Web Dynpro component usage concept. A component which gets a reference to the component usage managed by another component can 'abuse' this referenced by destroying the reference component instance. Web Dynpro does not provide a marker interface for a component usage so that another component can just reference but not destroy the related component instance.

Your scenario resembles my first Web Dynpro componentization sample application demonstrating how to enter a model component usage in "referencing mode". Two UI Components reference the same model component usage managed by the root component. But they should never ever destroy this instance on their own.

In case a client component does no longer need an instance of the referenced service component it can throw an event to which the service component is subscribed. In case no client component is active any more the service component could potentially destroy the component instance of the exposed component usage on its own.

Regards Bertram

Former Member
0 Kudos

Hi everybody,

I want to destroy used component instance WDb or WDc from WDa.

WDb and WDc have a back button linked with WDa plug "fromUsedComp". This Plug has a parameter "UsedCompName" which contains the name of the used component that triggers the plug. Inside the event handler "onPlugfromUsedComp" I want to evaluate the input parameter and destroy the corresponding used component instance.

Currently I'm using some if statement to evaluate the parameter and the typed APIs to destroy the used component instance but this means that I need to add some statement for each used component added. What I'd like to do is a more generic destroyer that will search the used component by its name (the input parameter) and then destroy its instance.

Yours and any other help is really appreciated,

Stefano