cancel
Showing results for 
Search instead for 
Did you mean: 

How I can call controller's functions from another component?

former_member186148
Active Participant
0 Kudos

Hi again!

I make a few web Dynpro components, for example first for user-data processing, second - for project-data processing. In the controller of 1-st controller there is a function getUserById(). In the controller of 2-nd component I need such function. And I don't want to make a dublicate for this function in the controller of 2-nd component. Is there a way to call function in one component from another?

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

are you talking about DC Projects or normal components in normal projects?

To access a function from another controller, you have to add the controller to Used WebDynpro Components in the controller where you want to call the functions. After you have done that, you have to add this used controller in the property tab of the controller where you want to call the function.

You can call the method then by writing something like: wdThis.wdgetMyOtherComponent.getUserById();

If you have en external DC you have to add the DC under used DC's before you can add the component under Used WebDynpro Components

Regards,

Dennis

Answers (3)

Answers (3)

former_member186148
Active Participant
0 Kudos

Hi! Big thanks to All for your answers!

My goal is reusing intro components in Web Dynpro (not Development Component) project type.

To Siva - something was wrong when I tried to realize your method. I think that somewhere I made a mistake

To Dennis - your method give to me needed result!

To Malyala - I didn't use your method but I want to thank you anyway

Regards, Lev

Former Member
0 Kudos

HI Lev,

Follow below steps

I assueme that both are different DC's

1)In 2-nd component declare first component as a used DC

2)Expose first component package in public parts of first component

3)Add the method you want to use in 2nd component to interface controller of first component

4)In the 2nd component controller add 1st component interface controller as a required controller.

5)Now you have access to data of component 1 in component 2

former_member197348
Active Contributor
0 Kudos

Hi,

Yes, you can reuse the component. There are two basic types of component communication. 1. Intra Component communication 2.Inter Component communication.

1. Intra Component communication: The two components must be in same DC(project).

Procedure:Say there are C1,C2 components in a DC.

Open C2, Open interface controller, create a similar (_parameters and return type_) method to the method C2. Call C2's method in this Interface method.

Open C1, select and right click Used Web Dynpro Components -> Add Used Component. In the wizard, you can browse and select the C2 component,and enter a name to the usage. Then the usage of the interface <b>must </b>be added in properties required controllers of a view/component controller.

Now we can use the method that is available in the C1 interface controller.

You must define method before declaring usage

<b>2.Inter Component communication:</b> The two components are in different DCs

Open DC metadata of C2. Right click on Public part-> create new Public Part.Enter name-> Next -> Select entity type as Web Dynpro Component in wizard,in Select Entities select the component ,Finish.

A structure for public part is created.

Open C1, Open DC metadata of C1. Right click on Used Dcs-> AddUsed DC. Browse to C2's public part.

Select Finish.

regards,

Siva

Edited by: Siva Rama Krushna on Dec 19, 2007 10:07 AM