How to dynamically create, edit, display UI elements in WebDynpro

...Previous

16)  This is how we can implement the interface

17)  Click on reimplement button

18)  Implement the interface in the second component and all the methods declared in the interface will get copied to the second component.

19)  Here write the below code to make the input field visible dynamically.

20)  Write the below code in ‘WDDOMODIFY’ method of the view of first component and call the method

21)  Save and activate all the components and interface. And then create an application for the first component.

22)  Now test the application.

23)  The input field gets visible dynamically. We have instantiated the component which has implemented the interface and called the corresponding method to reflect the changes dynamically.

Summary:  Here we can dynamically create, edit, display UI elements of a view  using interface.

Component C1 use the interface Z1 and instantiate it based on some condition i.e. dynamically .Within the interface the methods are declared. Component C2 implements the interface and defines the methods declared in the above mentioned interface Z1. In the component C1 the methods of C2 are called based on some condition.

Source code.

In ‘ZMAIN_COMPONENT’

method WDDOINIT .
  
data LO_CMP_USAGE type ref to IF_WD_COMPONENT_USAGE.

  LO_CMP_USAGE 
=   WD_THIS->WD_CPUSE_INTERFACE( ).
  
if LO_CMP_USAGE->HAS_ACTIVE_COMPONENT( ) is initial.
    LO_CMP_USAGE
->CREATE_COMPONENT'ZSECOND_COMPONENT' ).
     WD_THIS
->LO_INTERFACE WD_THIS->WD_CPIFC_INTERFACE( ).
  
endif.

endmethod.

In ‘ZMAIN_COMPONENT’

method WDDOMODIFYVIEW .
  
IF first_time EQ abap_true .

    
if  wd_comp_controller->LO_INTERFACE is not INITIAL.
      wd_comp_controller
->LO_INTERFACE->change_ui(
        im_context 
=   wd_context
        im_view 
=       view       ).
    
endif.

  
ENDIF.
endmethod.

IN ‘ZSECOND_COMPONENT’

method CHANGE_UI .
  
DATA:   lo_inpbox TYPE REF TO cl_wd_input_field.

  lo_inpbox ?= im_view
->get_elementid 'NAME_INPUT' ).
  
IF lo_inpbox IS NOT INITIAL.
    lo_inpbox
->set_visible'02' ) .
  
ENDIF.

endmethod.

 

Please send us your feedback/suggestions at webmaster@SAPTechnical.COM 

HomeContribute About Us Privacy Terms Of Use • Disclaimer • SafeCompanies: Advertise on SAPTechnical.COM | Post JobContact Us  

Graphic Design by Round the Bend Wizards

footer image footer image