Skip to Content
avatar image
Former Member

Making UI elements visible at runtime based on events.

Hi experts,

I am new to Web Dynpro Abap. My requirement is I have 2 drop down elements(Location and Sub-location.) Sub-location drop down is intially made visible-none. At run time I want sub-location to be visible based on the selected value of Location.

Providing exercise materials would be helpfull.

Regards,

Vinod

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

6 Answers

  • Best Answer
    avatar image
    Former Member
    Oct 09, 2009 at 09:36 AM

    hi Vinod ,

    u cn use the visibility attribute for the same .

    1 In the onSelect property of ur 1st dropdown "location" ,make a event

    2 thn in the onaction of that event , I mean in the method onActionEvent , u write this code to make the 2nd dropdwn invisible or visible , as follow :

    U have ur dropdown Sub Laocation

    for this UI element ,, bind it to the attribute wdui_visibility

    u can declare a context attribute of type wdui_visibility and bind its(UI element's) VISIBLE property with this attribute

    set the attribute value to 02 to make the dropdown visible

    
       DATA lo_nd_cn_visiblesuper TYPE REF TO if_wd_context_node.
        DATA lo_el_cn_visiblesuper TYPE REF TO if_wd_context_element.
        DATA ls_cn_visiblesuper TYPE wd_this->element_cn_visiblesuper.
        DATA lv_ca_visible LIKE ls_cn_visiblesuper-ca_visible.
    *   navigate from <CONTEXT> to <CN_VISIBLESUPER> via lead selection
        lo_nd_cn_visiblesuper = wd_context->get_child_node( name = wd_this->wdctx_cn_visiblesuper ).
     
    *   get element via lead selection
        lo_el_cn_visiblesuper = lo_nd_cn_visiblesuper->get_element(  ).
     
    *   get single attribute
        lo_el_cn_visiblesuper->set_attribute(
          EXPORTING
            name =  `CA_VISIBLE`
       
            value = '02').
    

    u can set this attribute :

    01- To make it invisible

    02 - To make it visible.

    here I have created a attribute ca_visible under node cn_visiblesuper of type wdui_visibility type ,which I am setting to 01

    to make table invisible this is binded to VISIBLE property of ur table UI

    instead of setting the context attribute value to '01' and '02' , u can also proceed by this way:

    wd_context->set_attribute( name = '<attribute name>' value = if_wdl_core=>visibility_visible )." to make it visible.

    wd_context->set_attribute( name = '<attribute name>' value = if_wdl_core=>visibility_none ). "to make it invisible

    regards,

    amit

    Edited by: amit saini on Oct 9, 2009 11:41 AM

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Oct 09, 2009 at 10:29 AM

    Hi amit,

    The first drop downi created a event called ONACTIONONSELECT_SW_CLASS.

    I created a attribute 'SUBCLASS_VISIBLE' of type wdui_visibility.

    I have done the coding as below in the event of the first drop down

    method ONACTIONONSELECT_SW_CLASS .

    DATA lo_nd_catalog TYPE REF TO if_wd_context_node.

    DATA lo_el_catalog TYPE REF TO if_wd_context_element.

    DATA ls_catalog TYPE wd_this->element_catalog.

    DATA lv_software_class TYPE wd_this->element_catalog-software_class.

    • navigate from <CONTEXT> to <CATALOG> via lead selection

    lo_nd_catalog = wd_context->get_child_node( name = wd_this->wdctx_catalog ).

    • @TODO handle non existant child

    • IF lo_nd_catalog IS INITIAL.

    • ENDIF.

    • get element via lead selection

    lo_el_catalog = lo_nd_catalog->get_element( ).

    • @TODO handle not set lead selection

    IF lo_el_catalog IS INITIAL.

    ENDIF.

    • get single attribute

    lo_el_catalog->get_attribute(

    EXPORTING

    name = `SOFTWARE_CLASS`

    IMPORTING

    value = lv_software_class ).

    if lv_software_class is not INITIAL.

    wd_context->set_attribute(

    name = 'SUBCLASS_VISIBLE'

    value = '02' ).

    ELSE.

    lo_el_catalog->set_attribute(

    name = 'SUBCLASS_VISIBLE'

    value = '01' ).

    ENDIF.

    endmethod.

    I am getting run time error as below:

    500 SAP Internal Server Error

    ERROR: Could not find attribute SUBCLASS_VISIBLE (termination: RABAX_STATE)

    Can you suggest me whats wrong in the code.

    Regards,

    Vinod

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      I hope you have binded 'SUBCLASS_VISIBLE' to second dropdown's Visible property.

      The code which you have written :

      • get single attribute

      lo_el_catalog->get_attribute(

      EXPORTING

      name = `SOFTWARE_CLASS`

      IMPORTING

      value = lv_software_class ).

      if lv_software_class is not INITIAL.

      wd_context->set_attribute( <I think in a hurry you copied wrong thing.>

      name = 'SUBCLASS_VISIBLE'

      value = '02' ).

      You should use Code Wizard to read/set the values.

      For Code wizard : press Control + F7 and read/set the Context attribute "SOFTWARE_CLASS" .

      Edited by: Saurav Mago on Oct 9, 2009 4:11 PM

  • avatar image
    Former Member
    Oct 09, 2009 at 09:40 AM

    Hi,

    Write the code in the onselect event of the first drop down.

    get the value of the drop down and based on this value hide the second drop down

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Oct 09, 2009 at 09:53 AM

    hi,

    Follow this approach :

    1. Make a attribute of type wdui_visibility and bind this to your second dropdown "Sub-Location"

    2. Now based on values selected in First Drop down, write the code in OnSelect event of first drop down "Location" and set the visible property of "Sub-location" as 01.

    for Visible : Set the attribute 02.

    for invisible : 01.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Oct 09, 2009 at 10:16 AM

    FYI, if u r using the dropdown by index , thn u cn bind the texts property of ur dropdown by index to a attribute of type

    string , to read the dropdown value using get attribute :

     DATA lo_nd_cn_role TYPE REF TO if_wd_context_node.
        DATA lo_el_cn_role TYPE REF TO if_wd_context_element.
        DATA ls_cn_role TYPE wd_this->element_cn_role.
        DATA lv_role_desc LIKE ls_cn_role-role_desc.
    *   navigate from <CONTEXT> to <CN_ROLE> via lead selection
        lo_nd_cn_role = wd_context->get_child_node( name = wd_this->wdctx_cn_role ).
    
    
    *   get single attribute
        lo_el_cn_role->get_attribute(
          EXPORTING
            name =  `ROLE_DESC`
          IMPORTING
            value = lv_role_desc ).
    

    here role_desc of type string , I have declared under node cn_role of cardinality 0:n

    u can read attributes using code wizard , by pressing CTRL + F7 and checking the radio button read context node/attributes

    u shud try to play with the code wizard in WDA 😊

    regards,

    amit

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Oct 09, 2009 at 11:11 AM

    Hi all,

    The issue is solved. Thank you for your response. Really appreciate all of you for sharing your views :). It really helped 😊

    Regards,

    Vinod

    Add comment
    10|10000 characters needed characters exceeded