cancel
Showing results for 
Search instead for 
Did you mean: 

How to call method of one View into another view?

Former Member
0 Kudos

Hi Gurus,

I am having 2 views defined in a main window say view1 & view2 i have method get_data defined in view1 & now want to call it in view2.

Is this possible?

Can this is also possible if the 2 views belong to a different window?

Regards

Rahul

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

^Hi Rahul.

You can not call this method in view2. You should define this method in the component controller tobe able to call it in view2.

Cheers,

Sascha

mohammed_anzys
Contributor
0 Kudos

Hi

Yep ,i misunderstood the question.You have to put the method in the component controller and you could call it in both the views.

Thanks

Anzy

Former Member
0 Kudos

Hi Sascha

Thankx for the prompt reply.

but can you provide me the sample code for it?

that would be of great help.

Regards,

Rahul

Former Member
0 Kudos

The component controller reference will be available as an instance attribute in all your view controllers. The attribute is wd_comp_controller.

If your method is get_data, then call the method as <b>wd_comp_controller->get_data.</b>

You could simply use the code wizard with the option 'call method in used controller'.

Regards,

Nithya

Former Member
0 Kudos

Hi.

what type of sample code do you need? You do already have the method.

What ever you do in it do it in the component controller.

when calling it from the view instead of wd_this->get_data call wd_comp_controller->get_data( ).

What data do you fetch in this method?

If you just read context data you have to put these nodes in the component controller context also to share it between multiple views.

If you need more info just paste the code of the get data method and explain what you are doing in it.

Cheers,

Sascha

mohammed_anzys
Contributor
0 Kudos

Hi Rahul,

First of all , you need to create the context attributes in your component controller rather than creating those in the view.In the next step map this context data into your views.Now go to your component controller and write your method.

Now you could call this method in your views by wd_comp_controller->get_data( ).

Everything depends on your business logic.

Thanks

Anzy

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi Rahul,

Methods defined in one view cannot be called from another. If the method is common, define it in the component controller and call it as wd_comp_controller->method_name. Or even better, use an assistance class and have your method there.

Or if you just want to pass data between the views, you dont need the method. The component controller context is enough.

Regards

Nithya

mohammed_anzys
Contributor
0 Kudos

Hi

If the views are in the same window , you could call using the outbound plugs.

if you want to show the a view inside another view.You could use ViewContainer and embedd the view.

Thanks

Anzy