cancel
Showing results for 
Search instead for 
Did you mean: 

How to get references of view controllers

Former Member
0 Kudos

I want to use the following code to validate user input of the required fields on the page:

<b>lr_view_controller = wd_this->wd_get_api( ).

cl_wd_dynamic_tool=>check_mandatory_attr_on_view( view_controller = lr_view_controller ).</b>

Currently, I have 6 views in my component, V_Main contains V_1, V_2,...,V5. and all these required fields are in V_1 to V_5 while the submit button is in V_Main. I don't know how to get reference to the views which is not the current view. Any one can help? Can I refer these views by using "LOOP AT ..." or something else?

Thanks in advance.

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi, all

Thank you very much for your help. Finally, I solved my problem. I put the follow code in each DOBEFOREACTION method of each view and then all the views can get the validation check.

<b>lr_view_controller = wd_this->wd_get_api( ).

cl_wd_dynamic_tool=>check_mandatory_attr_on_view( view_controller = lr_view_controller ).</b>

Thank you very much indeed

mohammed_anzys
Contributor
0 Kudos

Hi Jaddy,

What you could do is , create five view variables in the component controller like

lv_view1, view2...like that , and add a code in each view's domodify to set these values to the component controller.And you could access these in your main view.

Thanks

Anzy

Award points if this solves your problem

Former Member
0 Kudos

Hi Jaddy,

I dont think there is a way to get the reference to another view. However, you can try to validate your fields by validating the context attributes of all the views (since all the context attributes are mapped from the component controller).

To get the handle to the component controller's context, use the following code:

DATA comp_context type ref to IF_WD_CONTEXT.
DATA wd_comp_controller type ref to IG_COMPONENTCONTROLLER.
comp_context = wd_comp_controller->wd_get_api( )->get_context( ).

Hope this helps.

Regards,

Ram

Former Member
0 Kudos

Hi, Ramalingam

Thanks for your reply.

But I want to use the following code to check the required fields, it seems it needs a view_controller as parameter, how can I make a validation if I use the context?

<b>cl_wd_dynamic_tool=>check_mandatory_attr_on_view( view_controller = lr_view_controller ).</b>

Thanks

Former Member
0 Kudos

Hi Jaddy,

If you use the context, you have to manually do the validation as you would do for any other variable. There is another option you can use. The steps are as below:

1. Create a new node in the context (view handlers).

2. Add 6 attributes of type IF_VIEW_NAME (for all view).

3. In each of the view's WdOnInit method, assign the 'wd_this' (refers to the current view) into the corresponding attribute in the view_handlers node of the context.

4. Read the handler to the view controller from this context when you need the view controller.

Regards,

Ram

mohammed_anzys
Contributor
0 Kudos

Hi

You should not set the attributes at the DOINIT, as the view will not be created that time.So what i suggest is , create it DOMODIFY .

As i said in my previous post , create five attributes in the component controller.

like l_view1,l_view2,l_view3...etc. of type if_wd_view_controller.

And now go to each view's modify method. And write the following code.

Data: lo_api TYPE REF TO if_wd_view_controller.

If first_time = 'X'.

lo_api = wd_this->wd_get_api( ).

wd_Comp_Controller->l_view1 = lo_api.

endif

And you could access this view controller , anywhere u want by using wd_Comp_Controller->l_view1

Thanks

Anzy

Award points if this solves your issue.

Message was edited by:

Mohammed Anzy S