cancel
Showing results for 
Search instead for 
Did you mean: 

Can't get window reference in used component

former_member185943
Participant
0 Kudos

Hi,

I have a window which embeds a view of a used Z component. I am using the window as popup, that is, I am creating it as:

lo_window = lo_window_manager->create_window(
                window_name = 'USED_COMPONENT'
                title       = l_title
                button_kind = if_wd_window=>co_buttons_okcancel ).
  lo_window->open( ).

Then, in the used component's WDDOINIT I am trying to register OK button to an action like:

lo_view_api       = wd_this->wd_get_api( ).
  lo_window_ctlr    = lo_view_api->get_embedding_window_ctlr( ).
  lo_window         = lo_window_ctlr->get_window( ).
  IF lo_window IS BOUND.
    lo_window->subscribe_to_button_event(
                button            = if_wd_window=>co_button_ok
                action_view       = lo_view_api
                action_name       = 'BUTTON_OK_PRESSED'
                is_default_button = abap_true ).
  ENDIF.

However, my lo_window reference remains initial, that is, the get_window method returns nothing. Everything else works good and even this works good if I have a window within the original WD component. But if I do it with used component, I can't get the window reference.

Any ideas?

Thanks!

KR,

Igor

Edited by: Igor Barbaric on Jul 8, 2009 3:09 PM

Note that these 2 code portions do NOT belong to the same method so the lo_window variable is not the same.

Accepted Solutions (1)

Accepted Solutions (1)

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

I believe that the problem is the fact that the inner component WDDOINIT gets called before the component is actually embedded into the window.

You would likely have to try a later event - like perhaps the WDDOINIT of the View.

I've personally taken a different approach in the past. When I have had a component usage to emebed, I didn't create a static window for it. I used the create_window_for_cmp_usage API.

DATA: l_ref_cmp_usage TYPE REF TO if_wd_component_usage.

l_ref_cmp_usage = wd_this->wd_cpuse_faculty_details( ).

IF l_ref_cmp_usage->has_active_component( ) IS INITIAL.

l_ref_cmp_usage->create_component( ).

ENDIF.

DATA: l_ref_interfacecontroller TYPE REF TO ziwci_cs_course_faculty_dtl .
  l_ref_interfacecontroller =   wd_this->wd_cpifc_faculty_details( ).
  l_ref_interfacecontroller->external_initialization(
    faculty_id = item_faculty_id ).

  DATA: l_window_manager TYPE REF TO if_wd_window_manager,
        l_cmp_api        TYPE REF TO if_wd_component,
        l_window         TYPE REF TO if_wd_window.
  DATA: l_text_t01 TYPE string.
  l_text_t01 =
    wd_assist->if_wd_component_assistance~get_text( 'T01' ).

  l_cmp_api        = wd_comp_controller->wd_get_api( ).
  l_window_manager = l_cmp_api->get_window_manager( ).
  l_window         = l_window_manager->create_window_for_cmp_usage(
                     interface_view_name    = 'W_POPUP_DTL'
                     component_usage_name   = 'FACULTY_DETAILS'
                     title                  = l_text_t01
                     message_display_mode   = if_wd_window=>co_msg_display_mode_selected ).

  l_window->open( ).

Notice that I call an interface method (external_initialization) of my inner component. You could also call this method after the window_open and even pass a reference of the window object into the method. This might be a workaround to your problem.

former_member185943
Participant
0 Kudos

Thanks, Thomas!

I simply replaced my method lo_window_manager->create_window(...) with what you suggested: lo_window_manager->create_window_for_cmp_usage(...). Everything else remained the same and now it works!

It's even better because I have one static window less. However, I still don't understand why previous version did not work. I didn't mention in my initial post, but the method WDDOINIT was already in the view, like you suggested. Still, the used component couldn't see the window. What is the difference between the windows produced by the two methods? Weird.

KR,

Igor

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

My guess is that it has to do with the order in which things are processed within the framework. By declaring the secondary window and embedding the view within it at design time, the initialization was likely happening much earlier than the more dynamic embedding used by the create_window_for_cmp_usage.

Answers (0)