cancel
Showing results for 
Search instead for 
Did you mean: 

How to make standard button invisible in a View dynamically?

Former Member
0 Kudos

Hi,

I have got the following requirement.

I have called a component from my enhanced standard component.In the output View,I need to make 3 standard buttons invisible.

I cannot not delete the UI elements since they are being already used in some other component. There are no binding properties already available and system is not allowing to bind properties to those buttons.

Please advice on what to write in the WDDOMODIFYVIEW of that view to make those buttons invisible. I can write the bypass code to happen the invisibility only on my requirement.

I got this following code from 

IWDBotton btn = (iWDButton) view.getElement("<your  button iD>");

btn.setEnabled(false);

But unable to decipher it and also it has syntax error

Accepted Solutions (1)

Accepted Solutions (1)

former_member211591
Contributor
0 Kudos

Hi,

if you are using Webdynpro Java, please post your question there.

regards

Former Member
0 Kudos

I am using ABAP Webdynpro in PPM

ramakrishnappa
Active Contributor
0 Kudos

Hi Kishore,

You can achieve your requirement as below


  • Enhance the view and user either PostExit or OverWrite of method WDDOMODIFYVIEW( ) of view
  • Identify the name of the buttons in view layout
  • Get the element from view by using VIEW reference
  • Now, set the property VISIBLE of the element

Example:  Let us say we have button names as BTN_DISPLAY, BTN_BACK, etc

    


   DATA lo_ui_element      type ref to CL_WD_UIELEMENT.

      DATA lo_container       TYPE REF TO cl_wd_uielement_container.


" get root container

     lo_container ?= view->get_root_element( ).

    

" get button reference

     lo_ui_element ?= lo_container->get_element( 'BTN_DISPLAY' ).

    

"Hide the element

     lo_ui_element->set_visible( cl_wd_uielement=>e_visible-none ).

"Repeat the same for other buttons as well

Please refer the below link for more information:

----------------------------------------

You can also hide the buttons by using customization of WD component.

Please refer the below link

Customize view fields using application configuration in Webdynpro ABAP

Hope this helps you.

Regards,

Rama

Former Member
0 Kudos

Hi Ramakrishna,

I have tried doing that but it is throwing the following error.

It is coming both in post exit /overwrite exit of WDDOMODIFY view

Method "GET_ELEMENT" is unknown or PROTECTED or PRIVATE.
ramakrishnappa
Active Contributor
0 Kudos

Hi Kishore,

Could you share the release of your system.

You can also hide the buttons by using customization:

Please refer the below link

Customize view fields using application configuration in Webdynpro ABAP

Hope this helps you.

Regards,

Rama

Former Member
0 Kudos

Hi,

SAP EHP 2 for SAP NetWeaver 7.0

We are told not to do with configuration

ramakrishnappa
Active Contributor
0 Kudos

Hi Kishore,

We have below options to achieve your requirement

  1. Hide buttons in the layout editor using enhancement - You do not want to do, as its used in other component
  2. Hide the buttons by using get_element and set visibility property -
  3. Hide the buttons by using customization concept - You are told not to do configuration

Please try the below steps for option 2


DATA lt_children        TYPE cl_wd_uielement=>tt_uielement.

DATA lo_container   TYPE REF TO cl_wd_uielement_container.

FIELD-SYMBOLS: <fs_ui_element> TYPE REF TO cl_wd_uielement.

CLEAR lt_children.

lo_container ?= view->get_root_element( ).

  lt_children = lo_container->get_children( ).

  LOOP AT lt_children ASSIGNING <fs_element>.

  IF <fs_element>-id = 'BTN_DISPLY' OR

  <fs_element>-id = 'BTN_BACK'.

  <fs_element>->set_visible( cl_wd_uielement=>e_visible-NONE ).

  ENDIF.

   ENDLOOP.

Hope this helps you.

Regards,

Rama

Former Member
0 Kudos
"<FS_ELEMENT>" is an object reference and therefore does not have any
components called "ID".

Getting this error..I went to the referred class cl_wd_uielement. it has GET_ID, even that also throwing same error. How to define that?

ramakrishnappa
Active Contributor
0 Kudos

Hi Kishore,

Sorry, it should be like this <fs_element>->id


DATA lt_children        TYPE cl_wd_uielement=>tt_uielement.

DATA lo_container   TYPE REF TO cl_wd_uielement_container.

FIELD-SYMBOLS: <fs_ui_element> TYPE REF TO cl_wd_uielement.

CLEAR lt_children.

lo_container ?= view->get_root_element( ).

  lt_children = lo_container->get_children( ).

  LOOP AT lt_children ASSIGNING <fs_element>.

  IF <fs_element>->id = 'BTN_DISPLY' OR

  <fs_element>->id = 'BTN_BACK'.

  <fs_element>->set_visible( cl_wd_uielement=>e_visible-NONE ).

  ENDIF.

   ENDLOOP.

Regards,

Rama

Former Member
0 Kudos

Hi Ramakrishnappa

I have pasted the code and in debug mode I have changed the button ID to the ID which I need to be hidden/invisible. But to my surprise I am just seeing the empty screen like below

ramakrishnappa
Active Contributor
0 Kudos

Hi Kishore,

It seems like all the child elements are hidden. Please check that buttons are available in the lt_children. Hide only buttons not the other elements.

Please try debugging and check again.

Regards,

Rama

Former Member
0 Kudos

Yes ..Child elements are hidden. It_children is having only 1 record with main ID but not child.

So in debug I have put my child button id and executed and that above empty screen came

ramakrishnappa
Active Contributor
0 Kudos

Hi Kishore,

Your view elements are structured inside many transparent containers. So, we need recursive search to find our element.

ROOT_UIELEMENT ----> TRANSAPRENT_CONTAINER---->.........>BTN_DISPLAY

Please check my document as below .. which uses recursive search

How to Hide UI Elements & Adjust View Layout Dynamically in Web Dynpro ABAP

If you need further assistance let me know. Also share snap shot the view elements structure from layout.

Regards,

Rama

ramakrishnappa
Active Contributor
0 Kudos

Hi Kishore,

Thanks for mailing the snap shot of view layout.

Your actual requirement : Dynamically hide the tool bar buttons in a table

Please write the below code in PostExit/OverWrite of WDDOMODIFY( ) of view


  DATA lo_root TYPE REF TO cl_wd_uielement_container.

  DATA lo_table  TYPE REF TO cl_wd_table.

  DATA lo_toolbar TYPE REF TO cl_wd_toolbar.

  DATA lt_items   TYPE if_wd_toolbar_item=>tt_toolbar_item.

  DATA LO_UI_EL TYPE REF TO CL_WD_UIELEMENT.

  FIELD-SYMBOLS <fs_items> LIKE LINE OF lt_items.

  lo_root ?= view->get_root_element( ).

  lo_table ?= lo_root->get_child( id = 'STAFFINGTABLE').

  lo_toolbar = lo_table->get_toolbar( ).

  lt_items = lo_toolbar->get_toolbar_items( ).

  LOOP AT lt_items ASSIGNING <fs_items>.

    lo_UI_EL ?= <fs_items>.

    if lo_ui_el IS BOUND AND

      ( lo_ui_el->id eq 'BTN_1' or

     lo_ui_el->id eq 'BTN_2' ).

    lo_ui_el->set_visible( value = cl_wd_toolbar_button=>e_visible-none ).

    ENDIF.

  ENDLOOP.

Note: Replace tool bar buttons BTN_1, BTN_2 as per your requirement

Hope this resolves your issue.

Regards,

Rama

Answers (1)

Answers (1)

NagaPrakashT
Contributor
0 Kudos

Kishore,

    You can enhance the view and create Pre-Exit method. Inside the method please write the below code.

DATA: ui_element TYPE REF TO if_wd_view_element,
          button       TYPE REF TO cl_wd_button.

   CALL METHOD view->get_element
     EXPORTING
       id      = 'BUTTON1' "( ID of UI Element in Layout)
     RECEIVING
       element = ui_element.


   button ?= ui_element."( Casting)

  CALL METHOD button->set_visible
    EXPORTING
      value  = '01' " Invisible.


Thanks,

Naga


Former Member
0 Kudos

Hi ,

The below highlighted line is throwing dump

DATA: ui_element TYPE REF TO if_wd_view_element,
          button       TYPE REF TO cl_wd_button.

   CALL METHOD view->get_element
     EXPORTING
       id      = 'BUTTON1' "( ID of UI Element in Layout)
     RECEIVING
       element = ui_element.


  button ?= ui_element."( Casting)

  CALL METHOD button->set_visible
    EXPORTING
      value  = '01' " Invisible.



Description :  Dynamic type conflict when assigning references

Former Member
0 Kudos

Hello Kishore,

Were you able to get the code to work?  I have a similar requirement to hide a button on a toolbar and tried the suggested code but received the same error on the button ?= ui_element."( Casting) statement.

Thank you in advance for any information you can provide.

Pat